home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 12 / Cream of the Crop 12 (Part II) / Cream of the Crop 12 (Part II).iso / OS2 / DIKUMUD.ZIP / DB.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-05-30  |  80.0 KB  |  3,456 lines

  1. /*
  2.   SillyMUD Distribution V1.1b             (c) 1993 SillyMUD Developement
  3.  
  4.   See license.doc for distribution terms.   SillyMUD is based on DIKUMUD
  5. */
  6.  
  7. #include <stdio.h>
  8. #include <string.h>
  9. #include <ctype.h>
  10. #include <time.h>
  11.  
  12. #include "protos.h"
  13.  
  14. #define NEW_ZONE_SYSTEM
  15. #define killfile "killfile"
  16.  
  17. /**************************************************************************
  18. *  declarations of most of the 'global' variables                         *
  19. ************************************************************************ */
  20. int top_of_scripts = 0;
  21. int top_of_world = 0;                 /* ref to the top element of world */
  22. #if HASH
  23. struct hash_header    room_db;
  24. #else
  25. struct room_data        *room_db[WORLD_SIZE];
  26. #endif
  27.  
  28. struct obj_data  *object_list = 0;    /* the global linked list of obj's */
  29. struct char_data *character_list = 0; /* global l-list of chars          */
  30.  
  31. struct zone_data *zone_table;         /* table of reset data             */
  32. int top_of_zone_table = 0;
  33. struct message_list fight_messages[MAX_MESSAGES]; /* fighting messages   */
  34. struct player_index_element *player_table = 0; /* index to player file   */
  35. int top_of_p_table = 0;               /* ref to top of table             */
  36. int top_of_p_file = 0;
  37. long total_bc = 0;
  38. long room_count=0;
  39. long mob_count=0;
  40. long obj_count=0;
  41. long total_mbc=0;
  42. long total_obc=0;
  43.  
  44. /*
  45. **  distributed monster stuff
  46. */
  47. int mob_tick_count=0;
  48. char wmotd[MAX_STRING_LENGTH];
  49. char credits[MAX_STRING_LENGTH];      /* the Credits List                */
  50. char news[MAX_STRING_LENGTH];            /* the news                        */
  51. char motd[MAX_STRING_LENGTH];         /* the messages of today           */
  52. char help[MAX_STRING_LENGTH];         /* the main help page              */
  53. char info[MAX_STRING_LENGTH];         /* the info text                   */
  54. char wizlist[MAX_STRING_LENGTH*2];      /* the wizlist                     */
  55. char login[MAX_STRING_LENGTH];
  56.  
  57.  
  58. FILE *mob_f,                          /* file containing mob prototypes  */
  59.      *obj_f,                          /* obj prototypes                  */
  60.      *help_fl;                        /* file for help texts (HELP <kwd>)*/
  61.  
  62. struct index_data *mob_index;         /* index table for mobile file     */
  63. struct index_data *obj_index;         /* index table for object file     */
  64. struct help_index_element *help_index = 0;
  65.  
  66. int top_of_mobt = 0;                  /* top of mobile index table       */
  67. int top_of_objt = 0;                  /* top of object index table       */
  68. int top_of_helpt;                     /* top of help index table         */
  69.  
  70. struct time_info_data time_info;    /* the infomation about the time   */
  71. struct weather_data weather_info;    /* the infomation about the weather */
  72.  
  73. int saved_rooms[29000];
  74. int number_of_saved_rooms = 0;
  75. extern struct descriptor_data *descriptor_list;
  76.  
  77.  
  78. /*************************************************************************
  79. *  routines for booting the system                                       *
  80. *********************************************************************** */
  81.  
  82.  
  83. /* body of the booting system */
  84. void boot_db()
  85. {
  86.     int i;
  87.     extern int no_specials;
  88.  
  89.     log("Boot db -- BEGIN.");
  90.  
  91.     log("Resetting the game time:");
  92.     reset_time();
  93.  
  94.     log("Reading newsfile, credits, help-page, info and motd.");
  95.     file_to_string(NEWS_FILE, news);
  96.     file_to_string(CREDITS_FILE, credits);
  97.     file_to_string(MOTD_FILE, motd);
  98.           file_to_string("wizmotd", wmotd);
  99.     file_to_string(HELP_PAGE_FILE, help);
  100.     file_to_string(INFO_FILE, info);
  101.     file_to_string(WIZLIST_FILE, wizlist);
  102.         file_to_string("login", login);
  103.  
  104.         log("Initializing Script Files.");
  105.  
  106.     /* some machines are pre-allocation specific when dealing with realloc */
  107.         script_data = (struct scripts *) malloc(sizeof(struct scripts));
  108.         CommandSetup();
  109.         InitScripts();
  110.     log("Opening mobile, object and help files.");
  111.     if (!(mob_f = fopen(MOB_FILE, "r")))    {
  112.         perror("boot");
  113.         assert(0);
  114.     }
  115.  
  116.     if (!(obj_f = fopen(OBJ_FILE, "r")))    {
  117.         perror("boot");
  118.         assert(0);
  119.     }
  120.     if (!(help_fl = fopen(HELP_KWRD_FILE, "r")))
  121.       log("   Could not open help file.");
  122.     else 
  123.       help_index = build_help_index(help_fl, &top_of_helpt);
  124.  
  125.     log("Loading zone table.");
  126.     boot_zones();
  127.  
  128.     log("Loading rooms.");
  129.     boot_world();
  130.  
  131.  
  132.     log("Generating index tables for mobile and object files.");
  133.     mob_index = generate_indices(mob_f, &top_of_mobt);
  134.     obj_index = generate_indices(obj_f, &top_of_objt);
  135.             
  136.     log("Renumbering zone table.");
  137.     renum_zone_table();
  138.  
  139.     log("Generating player index.");
  140.     build_player_index();
  141.  
  142.     log("Loading fight messages.");
  143.     load_messages();
  144.  
  145.     log("Loading social messages.");
  146.     boot_social_messages();
  147.  
  148.   log("Loading pose messages.");
  149.     boot_pose_messages();
  150.  
  151.     log("Assigning function pointers:");
  152.     if (!no_specials)    {
  153.         log("   Mobiles.");
  154.         assign_mobiles();
  155.         log("   Objects.");
  156.         assign_objects();
  157.         log("   Room.");
  158.         assign_rooms();
  159.     }
  160.  
  161.     log("   Commands.");    
  162.     assign_command_pointers();
  163.     log("   Spells.");
  164.     assign_spell_pointers();
  165.  
  166.     log("Updating characters with saved items:");
  167.     update_obj_file();
  168.         log("Loading saved rooms.");
  169.         ReloadRooms();
  170.  
  171. #if LIMITED_ITEMS
  172.         PrintLimitedItems();
  173. #endif
  174.     for (i = 0; i <= top_of_zone_table; i++)    {
  175.       char    *s;
  176.       int    d,e;
  177.       s = zone_table[i].name;
  178.       d = (i ? (zone_table[i - 1].top + 1) : 0);
  179.       e = zone_table[i].top;
  180.       fprintf(stderr, "Performing boot-time init of %s (rooms %d-%d).\n",
  181.           s, d, e);
  182.       zone_table[i].start = 0;
  183.  
  184.  
  185.       if (i == 0) {
  186.         fprintf(stderr, "Performing boot-time reload of static mobs\n",
  187.             s);
  188.         reset_zone(0);
  189.  
  190.       }
  191.  
  192.       if (i == 1) {
  193.         fprintf(stderr, "Automatic initialization of  %s\n", s);
  194.         reset_zone(1);
  195.       }
  196.     }
  197.  
  198.     reset_q.head = reset_q.tail = 0;
  199.  
  200.     log("Boot db -- DONE.");
  201. }
  202.  
  203.  
  204. /* reset the time in the game from file */
  205. /* reset the time in the game from file */
  206. void reset_time()
  207. {
  208.     char buf[80];
  209.         extern unsigned char moontype;
  210.     long beginning_of_time = 650336715;
  211.  
  212.  
  213.  
  214.     struct time_info_data mud_time_passed(time_t t2, time_t t1);
  215.  
  216.     time_info = mud_time_passed(time(0), beginning_of_time);
  217.  
  218.         moontype = time_info.day;
  219.  
  220.     switch(time_info.hours){
  221.         case 0 :
  222.         case 1 :
  223.         case 2 :
  224.         case 3 :
  225.         case 4 : 
  226.         {
  227.             weather_info.sunlight = SUN_DARK;
  228.                         switch_light(MOON_SET);
  229.             break;
  230.         }
  231.         case 5 :
  232.         case 6 :
  233.         {
  234.             weather_info.sunlight = SUN_RISE;
  235.             switch_light(SUN_RISE);
  236.             break;
  237.         }
  238.         case 7 :
  239.         case 8 :
  240.         case 9 :
  241.         case 10 :
  242.         case 11 :
  243.         case 12 :
  244.         case 13 :
  245.         case 14 :
  246.         case 15 :
  247.         case 16 :
  248.         case 17 :
  249.         case 18 :
  250.         {
  251.             weather_info.sunlight = SUN_LIGHT;
  252.             break;
  253.         }
  254.         case 19 :
  255.         case 20 :
  256.         {
  257.             weather_info.sunlight = SUN_SET;
  258.             break;
  259.         }
  260.         case 21 :
  261.         case 22 : 
  262.         case 23 :
  263.         default :
  264.         {
  265.           switch_light(SUN_DARK);
  266.           weather_info.sunlight = SUN_DARK;
  267.           break;
  268.         }
  269.     }
  270.  
  271.     sprintf(buf,"   Current Gametime: %dH %dD %dM %dY.",
  272.             time_info.hours, time_info.day,
  273.             time_info.month, time_info.year);
  274.     log(buf);
  275.  
  276.     weather_info.pressure = 960;
  277.     if ((time_info.month>=7)&&(time_info.month<=12))
  278.         weather_info.pressure += dice(1,50);
  279.     else
  280.         weather_info.pressure += dice(1,80);
  281.  
  282.     weather_info.change = 0;
  283.  
  284.     if (weather_info.pressure<=980) {
  285.            if ((time_info.month>=3) && (time_info.month<=14))
  286.         weather_info.sky = SKY_LIGHTNING;
  287.            else
  288.                 weather_info.sky = SKY_LIGHTNING;
  289.     } else if (weather_info.pressure<=1000) {
  290.            if ((time_info.month>=3) && (time_info.month<=14))
  291.         weather_info.sky = SKY_RAINING;
  292.            else
  293.         weather_info.sky = SKY_RAINING;
  294.     } else if (weather_info.pressure<=1020) {
  295.         weather_info.sky = SKY_CLOUDY;
  296.     } else {
  297.             weather_info.sky = SKY_CLOUDLESS;
  298.     }
  299. }
  300.  
  301.  
  302.  
  303. /* update the time file */
  304. void update_time()
  305. {
  306.   return;
  307. }
  308.  
  309.  
  310.  
  311. struct wizs {
  312.    char name[20];
  313.    int level;
  314. };
  315.  
  316. int intcomp(struct wizs *j, struct wizs *k) {
  317.    return (k->level - j->level);
  318. }
  319.      /* generate index table for the player file */
  320. void build_player_index()
  321. {
  322.   int nr = -1, i;
  323.   struct char_file_u dummy;
  324.   FILE *fl;
  325.   
  326.   char tempbuf[255];
  327.   char title[255], tmp2[255], blank[255];
  328.   char buf[MAX_STRING_LENGTH*2];
  329.  
  330.   register int max=0, j;
  331.   int center;
  332.  
  333.   struct wizlistgen list_wiz;
  334.   int number_level[9];
  335.  
  336.  
  337.   for(j = 0; j <= 10; j++)
  338.      list_wiz.number[j] = 0;
  339.  
  340.   for (i = 0; i <= 9; i++) number_level[i] = 0;
  341.   
  342.   if (!(fl = fopen(PLAYER_FILE, "rb+")))    {
  343.      perror("build player index");
  344.      exit(0);
  345.   }
  346.   
  347.   for (; !feof(fl);)    {
  348.     fread(&dummy, sizeof(struct char_file_u), 1, fl);
  349.     if (!feof(fl))   /* new record */          {
  350.       /* Create new entry in the list */
  351.       if (nr == -1) {
  352.     CREATE(player_table, 
  353.            struct player_index_element, 1);
  354.     nr = 0;
  355.       }    else {
  356.     if (!(player_table = (struct player_index_element *)
  357.           realloc(player_table, (++nr + 1) *
  358.               sizeof(struct player_index_element))))
  359.       {
  360.         perror("generate index");
  361.         exit(0);
  362.       }
  363.       }
  364.       
  365.       player_table[nr].nr = nr;
  366.       
  367.       CREATE(player_table[nr].name, char,
  368.          strlen(dummy.name) + 1);
  369.       for (i = 0; *(player_table[nr].name + i) = 
  370.        LOWER(*(dummy.name + i)); i++);
  371.  
  372.       for (i = 0; i <= 5; i++) if (dummy.level[i] >= 51) {
  373.     sprintf(buf,"GOD: %s, Levels [%d][%d][%d][%d][%d][%d]",dummy.name,
  374.         dummy.level[0],dummy.level[1],dummy.level[2],dummy.level[3],
  375.         dummy.level[4],dummy.level[5]);
  376.     log(buf);
  377.  
  378.     max = 0;
  379.      for (j=0 ; j < MAX_CLASS ; j++)
  380.        if (dummy.level[j] > max) {
  381.          max = dummy.level[j];    
  382.         }    
  383.      
  384.  
  385.         list_wiz.lookup[max - 51].stuff[list_wiz.number[max - 51]].name = 
  386.       (char *)strdup(dummy.name);
  387.         list_wiz.lookup[max - 51].stuff[list_wiz.number[max - 51]].title = 
  388.       (char *)strdup(dummy.title);
  389.         list_wiz.number[max - 51]++;
  390.     break;
  391.       }
  392.  
  393.     }
  394.   }
  395.  
  396.  
  397.   fclose(fl);
  398.   
  399.   top_of_p_table = nr;
  400.   
  401.   top_of_p_file = top_of_p_table;
  402.  
  403.   log("Began Wizlist Generation.");
  404.  
  405.   sprintf(wizlist, "\033[2J\033[0;0H\n\r\n\r");
  406.   sprintf(buf, "-* Creator and Supreme Being [%d/1] *-\n\r",list_wiz.number[9]);
  407.  
  408.   
  409.   center = (38 - (int) (str_len(buf)/2));
  410.   log("center computed.");
  411.   for(i = 0; i <= center; i++)
  412.      strcat(wizlist, " ");
  413.  
  414.   strcat(wizlist, buf);
  415.  
  416.  
  417.   for(i = 0; i < list_wiz.number[9]; i++) {
  418.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[9].stuff[i].name,
  419.              list_wiz.lookup[9].stuff[i].title);
  420.  
  421.      center = 38 - (int) (str_len(buf)/2);
  422.      for(j = 0; j <= center; j++)
  423.         strcat(wizlist, " ");
  424.      strcat(wizlist, buf);
  425.   }
  426.  
  427.   strcat(wizlist, "\n\r\n\r");
  428.   log("Creator Generated.");
  429.  
  430.   sprintf(buf, "-* Implementors [%d/4] *-\n\r", list_wiz.number[8]);
  431.   center = 38 - (int) (str_len(buf)/2);
  432.  
  433.   for(i = 0; i <= center; i++)
  434.      strcat(wizlist, " ");
  435.   strcat(wizlist, buf);
  436.  
  437.   for(i = 0; i < list_wiz.number[8]; i++) {
  438.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[8].stuff[i].name,
  439.              list_wiz.lookup[8].stuff[i].title);
  440.      center = 38 - (int) (str_len(buf)/2);
  441.      for(j = 0; j <= center; j++)
  442.         strcat(wizlist, " ");
  443.      strcat(wizlist, buf);
  444.   }
  445.  
  446.   strcat(wizlist, "\n\r\n\r");
  447.   log("Implementors Generated.");
  448.  
  449.   sprintf(buf, "-* Gods of Final Judgement [%d/6] *-\n\r", list_wiz.number[7]);
  450.   center = 38 - (int) (str_len(buf)/2);
  451.  
  452.   for(i = 0; i <= center; i++)
  453.      strcat(wizlist, " ");
  454.   strcat(wizlist, buf);
  455.  
  456.   for(i = 0; i < list_wiz.number[7]; i++) {
  457.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[7].stuff[i].name,
  458.              list_wiz.lookup[7].stuff[i].title);
  459.      center = 38 - (int) (str_len(buf)/2);
  460.      for(j = 0; j <= center; j++)
  461.         strcat(wizlist, " ");
  462.      strcat(wizlist, buf);
  463.   }
  464.  
  465.   strcat(wizlist, "\n\r\n\r");
  466.   log("Gods of Final Judgement Generated.");
  467.  
  468.   sprintf(buf, "-* Gods of Judgement [%d/8] *-\n\r", list_wiz.number[6]);
  469.   center = 38 - (int) (str_len(buf)/2);
  470.  
  471.   for(i = 0; i <= center; i++)
  472.      strcat(wizlist, " ");
  473.   strcat(wizlist, buf);
  474.  
  475.   for(i = 0; i < list_wiz.number[6]; i++) {
  476.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[6].stuff[i].name,
  477.              list_wiz.lookup[6].stuff[i].title);
  478.      center = 38 - (int) (str_len(buf)/2);
  479.      for(j = 0; j <= center; j++)
  480.         strcat(wizlist, " ");
  481.      strcat(wizlist, buf);
  482.   }
  483.  
  484.   strcat(wizlist, "\n\r\n\r");
  485.  
  486.  
  487.   sprintf(buf, "-* Greater Gods [%d/10] *-\n\r", list_wiz.number[5]);
  488.   center = 38 - (int) (str_len(buf)/2);
  489.  
  490.   for(i = 0; i <= center; i++)
  491.      strcat(wizlist, " ");
  492.   strcat(wizlist, buf);
  493.  
  494.   for(i = 0; i < list_wiz.number[5]; i++) {
  495.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[5].stuff[i].name,
  496.              list_wiz.lookup[5].stuff[i].title);
  497.      center = 38 - (int) (str_len(buf)/2);
  498.      for(j = 0; j <= center; j++)
  499.         strcat(wizlist, " ");
  500.      strcat(wizlist, buf);
  501.   }
  502.  
  503.   strcat(wizlist, "\n\r\n\r");
  504.  
  505.  
  506.   sprintf(buf, "-* Gods [%d/12] *-\n\r", list_wiz.number[4]);
  507.   center = 38 - (int) (str_len(buf)/2);
  508.  
  509.   for(i = 0; i <= center; i++)
  510.      strcat(wizlist, " ");
  511.   strcat(wizlist, buf);
  512.  
  513.   for(i = 0; i < list_wiz.number[4]; i++) {
  514.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[4].stuff[i].name,
  515.              list_wiz.lookup[4].stuff[i].title);
  516.      center = 38 - (int) (str_len(buf)/2);
  517.      for(j = 0; j <= center; j++)
  518.         strcat(wizlist, " ");
  519.      strcat(wizlist, buf);
  520.   }
  521.  
  522.   strcat(wizlist, "\n\r\n\r");
  523.  
  524.  
  525.   sprintf(buf, "-* Demi-Gods [%d/14] *-\n\r", list_wiz.number[3]);
  526.   center = 38 - (int) (str_len(buf)/2);
  527.  
  528.   for(i = 0; i <= center; i++)
  529.      strcat(wizlist, " ");
  530.   strcat(wizlist, buf);
  531.  
  532.   for(i = 0; i < list_wiz.number[3]; i++) {
  533.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[3].stuff[i].name,
  534.              list_wiz.lookup[3].stuff[i].title);
  535.      center = 38 - (int) (str_len(buf)/2);
  536.      for(j = 0; j <= center; j++)
  537.         strcat(wizlist, " ");
  538.      strcat(wizlist, buf);
  539.   }
  540.  
  541.   strcat(wizlist, "\n\r\n\r");
  542.  
  543.  
  544.   sprintf(buf, "-* Saints [%d/30] *-\n\r", list_wiz.number[2]);
  545.   center = 38 - (int) (str_len(buf)/2);
  546.  
  547.   for(i = 0; i <= center; i++)
  548.      strcat(wizlist, " ");
  549.   strcat(wizlist, buf);
  550.  
  551.   for(i = 0; i < list_wiz.number[2]; i++) {
  552.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[2].stuff[i].name,
  553.              list_wiz.lookup[2].stuff[i].title);
  554.      center = 38 - (int) (str_len(buf)/2);
  555.      for(j = 0; j <= center; j++)
  556.         strcat(wizlist, " ");
  557.      strcat(wizlist, buf);
  558.   }
  559.  
  560.   strcat(wizlist, "\n\r\n\r");
  561.  
  562.  
  563.   sprintf(buf, "-* Immortals of Creation [%d/50] *-\n\r", list_wiz.number[1]);
  564.   center = 38 - (int) (str_len(buf)/2);
  565.  
  566.   for(i = 0; i <= center; i++)
  567.      strcat(wizlist, " ");
  568.   strcat(wizlist, buf);
  569.  
  570.   for(i = 0; i < list_wiz.number[1]; i++) {
  571.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[1].stuff[i].name,
  572.              list_wiz.lookup[1].stuff[i].title);
  573.      center = 38 - (int) (str_len(buf)/2);
  574.      for(j = 0; j <= center; j++)
  575.         strcat(wizlist, " ");
  576.      strcat(wizlist, buf);
  577.   }
  578.  
  579.   strcat(wizlist, "\n\r\n\r");
  580.  
  581.  
  582.   sprintf(buf, "-* Immortals [%d/~] *-\n\r", list_wiz.number[0]);
  583.   center = 38 - (int) (str_len(buf)/2);
  584.  
  585.   for(i = 0; i <= center; i++)
  586.      strcat(wizlist, " ");
  587.   strcat(wizlist, buf);
  588.  
  589.   for(i = 0; i < list_wiz.number[0]; i++) {
  590.      sprintf(buf, "%s %s\n\r", list_wiz.lookup[0].stuff[i].name,
  591.              list_wiz.lookup[0].stuff[i].title);
  592.      center = 38 - (int) (str_len(buf)/2);
  593.      for(j = 0; j <= center; j++)
  594.         strcat(wizlist, " ");
  595.      strcat(wizlist, buf);
  596.   }
  597.  
  598.   strcat(wizlist, "\n\r\n\r");
  599.   max = 0;
  600.   for(i = 0; i <= 9; i++)
  601.     max += list_wiz.number[i];
  602.   sprintf(buf, "Total Gods: %d\n\r\n\r", max);
  603.   strcat(wizlist, buf);
  604.  
  605.   return;
  606. }
  607.  
  608.  
  609.  
  610.  
  611. /* generate index table for object or monster file */
  612. struct index_data *generate_indices(FILE *fl, int *top)
  613. {
  614.   int i = 0;
  615.   long bc=1500;
  616.   struct index_data *index;
  617.   char buf[82];
  618.   
  619.   rewind(fl);
  620.   
  621.   for (;;)    {
  622.     if (fgets(buf, sizeof(buf), fl))     {
  623.       if (*buf == '#')           {
  624.     if (!i)                         /* first cell */
  625.       CREATE(index, struct index_data, bc);
  626.     else
  627.       if (i >= bc) {
  628.         if (!(index = (struct index_data*) 
  629.         realloc(index, (i + 50) * sizeof(struct index_data)))) {
  630.           perror("load indices");
  631.           assert(0);
  632.         } 
  633.             bc += 50;
  634.           }
  635.     sscanf(buf, "#%d", &index[i].virtual);
  636.     index[i].pos = ftell(fl);
  637.     index[i].number = 0;
  638.     index[i].func = 0;
  639.     index[i].name = (index[i].virtual<99999)?fread_string(fl):
  640.       strdup("omega");
  641.     i++;
  642.       } else {
  643.     if (*buf == '$')    /* EOF */
  644.       break;
  645.       }
  646.     }    else      {
  647.     fprintf(stderr,"generate indices");
  648.     assert(0);
  649.     }
  650.   }
  651.   *top = i - 2;
  652.   return(index);
  653. }
  654.  
  655. void cleanout_room(struct room_data *rp)
  656. {
  657.   int    i;
  658.   struct extra_descr_data *exptr, *nptr;
  659.  
  660.   free(rp->name);
  661.   free(rp->description);
  662.   for (i=0; i<6; i++)
  663.     if (rp->dir_option[i]) {
  664.       free(rp->dir_option[i]->general_description);
  665.       free(rp->dir_option[i]->keyword);
  666.       free (rp->dir_option[i]);
  667.       rp->dir_option[i] = NULL;
  668.     }
  669.  
  670.   for (exptr=rp->ex_description; exptr; exptr = nptr) {
  671.     nptr = exptr->next;
  672.     free(exptr->keyword);
  673.     free(exptr->description);
  674.     free(exptr);
  675.   }
  676. }
  677.  
  678. void completely_cleanout_room(struct room_data *rp)
  679. {
  680.   struct char_data    *ch;
  681.   struct obj_data    *obj;
  682.   
  683.   while (rp->people) {
  684.     ch = rp->people;
  685.     act("The hand of god sweeps across the land and you are swept into the Void.", FALSE, NULL, NULL, NULL, TO_VICT);
  686.     char_from_room(ch);
  687.     char_to_room(ch, 0);    /* send character to the void */
  688.   }
  689.   
  690.   while (rp->contents) {
  691.     obj = rp->contents;
  692.     obj_from_room(obj);
  693.     obj_to_room(obj, 0);    /* send item to the void */
  694.   }
  695.   
  696.   cleanout_room(rp);
  697. }
  698.     
  699. void load_one_room(FILE *fl, struct room_data *rp)
  700. {
  701.   char chk[50];
  702.   int   bc=0;
  703.   unsigned long int    tmp;
  704.  
  705.   struct extra_descr_data *new_descr;
  706.  
  707.   bc = sizeof(struct room_data);
  708.   
  709.   rp->name = fread_string(fl);
  710.   if (rp->name && *rp->name)
  711.      bc += strlen(rp->name);
  712.   rp->description = fread_string(fl);
  713.   if (rp->description && *rp->description)
  714.      bc += strlen(rp->description);
  715.   
  716.   if (top_of_zone_table >= 0) {
  717.     int    zone;
  718.     fscanf(fl, " %*d ");
  719.     
  720.     /* OBS: Assumes ordering of input rooms */
  721.     
  722.     for (zone=0;
  723.      rp->number > zone_table[zone].top && zone<=top_of_zone_table;
  724.      zone++)
  725.       ;
  726.     if (zone > top_of_zone_table) {
  727.       fprintf(stderr, "Room %d is outside of any zone.\n", rp->number);
  728.       assert(0);
  729.     }
  730.     rp->zone = zone;
  731.   }
  732.   fscanf(fl, " %d ", &tmp);
  733.   rp->room_flags = tmp;
  734.   fscanf(fl, " %d ", &tmp);
  735.   rp->sector_type = tmp;
  736.   
  737.   if (tmp == -1) { 
  738.     fscanf(fl, " %d", &tmp);
  739.     rp->tele_time = tmp;
  740.     fscanf(fl, " %d", &tmp);              
  741.     rp->tele_targ = tmp;
  742.     fscanf(fl, " %d", &tmp);
  743.     rp->tele_mask = tmp;
  744.     if (IS_SET(TELE_COUNT, rp->tele_mask)) {
  745.       fscanf(fl, "%d ", &tmp);
  746.       rp->tele_cnt = tmp;
  747.     } else {
  748.       rp->tele_cnt = 0;
  749.     }
  750.     fscanf(fl, " %d", &tmp);
  751.     rp->sector_type = tmp;
  752.   } else {
  753.     rp->tele_time = 0;
  754.     rp->tele_targ = 0;
  755.     rp->tele_mask = 0;
  756.     rp->tele_cnt  = 0;
  757.   }
  758.   
  759.   if (tmp == SECT_WATER_NOSWIM || tmp == SECT_UNDERWATER)  { /* river */
  760.     /* read direction and rate of flow */
  761.     fscanf(fl, " %d ", &tmp);
  762.     rp->river_speed = tmp;
  763.     fscanf(fl, " %d ", &tmp);
  764.     rp->river_dir = tmp;
  765.   } 
  766.  
  767.   if (rp->room_flags & TUNNEL) {  /* read in mobile limit on tunnel */
  768.     fscanf(fl, " %d ", &tmp);
  769.     rp->moblim = tmp;
  770.   }
  771.   
  772.   rp->funct = 0;
  773.   rp->light = 0; /* Zero light sources */
  774.   
  775.   for (tmp = 0; tmp <= 5; tmp++)
  776.     rp->dir_option[tmp] = 0;
  777.   
  778.   rp->ex_description = 0;
  779.   
  780.   while (1==fscanf(fl, " %s \n", chk)) {
  781.     static char    buf[MAX_INPUT_LENGTH];
  782.     switch (*chk) {
  783.     case 'D':
  784.       setup_dir(fl, rp->number, atoi(chk + 1));
  785.       bc += sizeof(struct room_direction_data);
  786. /*      bc += strlen(rp->dir_option[atoi(chk + 1)]->general_description);
  787.       bc += strlen(rp->dir_option[atoi(chk + 1)]->keyword);
  788. */
  789.       break;
  790.     case 'E': /* extra description field */
  791.  
  792.       CREATE(new_descr,struct extra_descr_data,1);
  793.       bc += sizeof(struct extra_descr_data);
  794.  
  795.       new_descr->keyword = fread_string(fl);
  796.       if (new_descr->keyword && *new_descr->keyword)
  797.          bc += strlen(new_descr->keyword);
  798.       else
  799.     fprintf(stderr, "No keyword in room %d\n", rp->number);
  800.  
  801.       new_descr->description = fread_string(fl);
  802.       if (new_descr->description && *new_descr->description)
  803.          bc += strlen(new_descr->description);
  804.       else
  805.     fprintf(stderr, "No desc in room %d\n", rp->number);
  806.  
  807.       new_descr->next = rp->ex_description;
  808.       rp->ex_description = new_descr;
  809.       break;
  810.     case 'S':    /* end of current room */
  811.  
  812. #if BYTE_COUNT
  813.   if (bc >= 1000)
  814.      fprintf(stderr, "Byte count for this room[%d]: %d\n",rp->number,  bc);
  815. #endif
  816.       total_bc += bc;
  817.       room_count++; 
  818. /*      if(IS_SET(rp->room_flags, SAVE_ROOM)) {
  819.          saved_rooms[number_of_saved_rooms] = rp->number;
  820.          number_of_saved_rooms++;
  821.       } */
  822.       {
  823.        FILE *fp;
  824.        char buf[255];
  825.  
  826.        sprintf(buf, "world/%d", rp->number);
  827.        fp = fopen(buf, "r");
  828.        if(fp) {
  829.           saved_rooms[number_of_saved_rooms] = rp->number;
  830.           number_of_saved_rooms++;
  831.           fclose(fp);
  832.     }
  833.       }
  834.       return;
  835.     default:
  836.       sprintf(buf,"unknown auxiliary code `%s' in room load of #%d",
  837.           chk, rp->number);
  838.       log(buf);
  839.       break;
  840.     }
  841.   }
  842. }
  843.   
  844.   
  845.  
  846. /* load the rooms */
  847. void boot_world()
  848. {
  849.   FILE *fl;
  850.   int virtual_nr, last;
  851.   struct room_data    *rp;
  852.  
  853.  
  854. #if HASH
  855.   init_hash_table(&room_db, sizeof(struct room_data), 2048);
  856. #else
  857.   init_world(room_db);
  858. #endif
  859.   character_list = 0;
  860.   object_list = 0;
  861.   
  862.   if (!(fl = fopen(WORLD_FILE, "r")))    {
  863.     perror("fopen");
  864.     log("boot_world: could not open world file.");
  865.     assert(0);
  866.   }
  867.  
  868.   last = 0;
  869.   while (1==fscanf(fl, " #%d\n", &virtual_nr)) {
  870.     allocate_room(virtual_nr);
  871.     rp = real_roomp(virtual_nr);
  872.     if (rp)
  873.       bzero(rp, sizeof(*rp));
  874.     else {
  875.       fprintf(stderr, "Error, room %d not in database!(%d)\n", 
  876.           virtual_nr, last);
  877.       assert(0);
  878.     }
  879.  
  880.     rp->number = virtual_nr;
  881.     load_one_room(fl, rp);
  882.     last = virtual_nr;
  883.   }
  884.   
  885.   fclose(fl);
  886. }
  887.  
  888.  
  889.  
  890.  
  891.  
  892. void allocate_room(int room_number)
  893. {
  894.   if (room_number>top_of_world)
  895.     top_of_world = room_number;
  896. #if HASH
  897.   hash_find_or_create(&room_db, room_number);
  898. #else
  899.   room_find_or_create(room_db, room_number);
  900. #endif
  901. }
  902.  
  903.  
  904.  
  905.  
  906.  
  907.  
  908. /* read direction data */
  909. void setup_dir(FILE *fl, int room, int dir)
  910. {
  911.   int tmp;
  912.   struct room_data    *rp, dummy;
  913.   
  914.   rp = real_roomp(room);
  915.   
  916.   if (!rp) {
  917.     rp = &dummy;            /* this is a quick fix to make the game */
  918.     dummy.number = room;   /* stop crashing   */
  919.   }
  920.   
  921.   CREATE(rp->dir_option[dir], 
  922.      struct room_direction_data, 1);
  923.   
  924.   rp->dir_option[dir]->general_description =
  925.     fread_string(fl);
  926.   rp->dir_option[dir]->keyword = fread_string(fl);
  927.   
  928.   fscanf(fl, " %d ", &tmp);
  929.   switch(tmp) {
  930.   case 1:
  931.     rp->dir_option[dir]->exit_info = EX_ISDOOR;
  932.     break;
  933.   case 2:
  934.     rp->dir_option[dir]->exit_info = EX_ISDOOR | EX_PICKPROOF;
  935.     break;
  936.   case 3:
  937.     rp->dir_option[dir]->exit_info = EX_ISDOOR | EX_SECRET;
  938.     break;
  939.   case 4:
  940.     rp->dir_option[dir]->exit_info = EX_ISDOOR | EX_SECRET |
  941.       EX_PICKPROOF;
  942.     break;
  943.   case 5:
  944.     rp->dir_option[dir]->exit_info = EX_CLIMB;
  945.     break;
  946.   case 6:
  947.     rp->dir_option[dir]->exit_info = EX_CLIMB | EX_ISDOOR;
  948.     break;
  949.   case 7:
  950.     rp->dir_option[dir]->exit_info = EX_CLIMB | EX_ISDOOR | EX_PICKPROOF;
  951.     break;
  952.   default:
  953.     rp->dir_option[dir]->exit_info = 0;
  954.   }
  955.   
  956.   fscanf(fl, " %d ", &tmp);
  957.   rp->dir_option[dir]->key = tmp;
  958.   
  959.   fscanf(fl, " %d ", &tmp);
  960.   rp->dir_option[dir]->to_room = tmp;
  961. }
  962.  
  963.  
  964. #define LOG_ZONE_ERROR(ch, type, zone, cmd) {\
  965.     sprintf(buf, "error in zone %s cmd %d (%c) resolving %s number", \
  966.         zone_table[zone].name, cmd, ch, type); \
  967.           log(buf); \
  968.           }
  969. void renum_zone_table()
  970. {
  971.   int zone, comm;
  972.   struct reset_com *cmd;
  973.   char    buf[256];
  974.   
  975.   for (zone = 0; zone <= top_of_zone_table; zone++)
  976.     for (comm = 0; zone_table[zone].cmd[comm].command != 'S'; comm++)
  977.       switch((cmd = zone_table[zone].cmd +comm)->command) {
  978.       case 'M':
  979.     cmd->arg1 = real_mobile(cmd->arg1);
  980.     if (cmd->arg1<0)
  981.       LOG_ZONE_ERROR('M', "mobile", zone, comm);
  982.     if(cmd->arg3<0)
  983.       LOG_ZONE_ERROR('M', "room", zone, comm);
  984.     break;
  985.       case 'C':
  986.     cmd->arg1 = real_mobile(cmd->arg1);
  987.     if (cmd->arg1<0)
  988.       LOG_ZONE_ERROR('C', "mobile", zone, comm);
  989.     /*cmd->arg3 = real_room(cmd->arg3);*/
  990.     if(cmd->arg3<0)
  991.       LOG_ZONE_ERROR('C', "room", zone, comm);
  992.     break;
  993.       case 'O':
  994.     cmd->arg1 = real_object(cmd->arg1);
  995.     if(cmd->arg1<0)
  996.       LOG_ZONE_ERROR('O', "object", zone, comm);
  997.     if (cmd->arg3 != NOWHERE) {
  998.       /*cmd->arg3 = real_room(cmd->arg3);*/
  999.       if(cmd->arg3<0)
  1000.         LOG_ZONE_ERROR('O', "room", zone, comm);
  1001.     }
  1002.     break;
  1003.       case 'G':
  1004.     cmd->arg1 = real_object(cmd->arg1);
  1005.     if(cmd->arg1<0)
  1006.       LOG_ZONE_ERROR('G', "object", zone, comm);
  1007.     break;
  1008.       case 'E':
  1009.     cmd->arg1 = real_object(cmd->arg1);
  1010.     if(cmd->arg1<0)
  1011.       LOG_ZONE_ERROR('E', "object", zone, comm);
  1012.     break;
  1013.       case 'P':
  1014.     cmd->arg1 = real_object(cmd->arg1);
  1015.     if(cmd->arg1<0)
  1016.       LOG_ZONE_ERROR('P', "object", zone, comm);
  1017.     cmd->arg3 = real_object(cmd->arg3);
  1018.     if(cmd->arg3<0)
  1019.       LOG_ZONE_ERROR('P', "object", zone, comm);
  1020.     break;                    
  1021.       case 'D':
  1022.     /*cmd->arg1 = real_room(cmd->arg1);*/
  1023.     if(cmd->arg1<0)
  1024.       LOG_ZONE_ERROR('D', "room", zone, comm);
  1025.     break;
  1026.       }
  1027. }
  1028.  
  1029.  
  1030. /* load the zone table and command tables */
  1031. void boot_zones()
  1032. {
  1033.  
  1034.   FILE *fl;
  1035.   int zon = 0, cmd_no = 0, expand, tmp, bc=100, cc = 22;
  1036.   char *check, buf[81];
  1037.   
  1038.   if (!(fl = fopen(ZONE_FILE, "r")))    {
  1039.     perror("boot_zones");
  1040.     assert(0);
  1041.   }
  1042.   
  1043.   for (;;)    {
  1044.     fscanf(fl, " #%*d\n");
  1045.     check = fread_string(fl);
  1046.     
  1047.     if (*check == '$')
  1048.       break;        /* end of file */
  1049.     
  1050.     /* alloc a new zone */
  1051.     
  1052.     if (!zon)
  1053.       CREATE(zone_table, struct zone_data, bc);
  1054.     else
  1055.       if (zon >= bc) {
  1056.         if (!(zone_table = (struct zone_data *) realloc(zone_table,
  1057.              (zon + 10) * sizeof(struct zone_data)))){
  1058.       perror("boot_zones realloc");
  1059.       assert(0);
  1060.     }
  1061.         bc += 10;
  1062.       }
  1063.     zone_table[zon].name = check;
  1064.     fscanf(fl, " %d ", &zone_table[zon].top);
  1065.     fscanf(fl, " %d ", &zone_table[zon].lifespan);
  1066.     fscanf(fl, " %d ", &zone_table[zon].reset_mode);
  1067.     
  1068.     /* read the command table */
  1069.  
  1070. /*
  1071.   new code to allow the game to be 'static' i.e. all the mobs are saved
  1072. in one big zone file, and restored later.
  1073. */
  1074. /*    if (zon == 0) { 
  1075.       tmp_fl = fl;
  1076.  
  1077.       fl = fopen("world/mobs","r");
  1078.       if (!fl) {
  1079.     log("No static mob file found.. continuing with normal boot");
  1080.     fl = tmp_fl;
  1081.       }
  1082.     }
  1083.   */  
  1084.     cmd_no = 0;
  1085.  
  1086.     if (zon == 0)
  1087.       cc = 20;
  1088.       
  1089.     for (expand = 1;;)         {
  1090.       if (expand)
  1091.     if (!cmd_no)
  1092.       CREATE(zone_table[zon].cmd, struct reset_com, cc);
  1093.     else
  1094.       if (cmd_no >= cc) {
  1095.         cc += 5;
  1096.         if (!(zone_table[zon].cmd =
  1097.           (struct reset_com *) realloc(zone_table[zon].cmd, 
  1098.                    (cc * sizeof(struct reset_com)))))  {
  1099.         perror("reset command load");
  1100.         assert(0);
  1101.           }
  1102.       }
  1103.       
  1104.       expand = 1;
  1105.       
  1106.       fscanf(fl, " "); /* skip blanks */
  1107.       fscanf(fl, "%c", 
  1108.          &zone_table[zon].cmd[cmd_no].command);
  1109.       
  1110.       if (zone_table[zon].cmd[cmd_no].command == 'S')
  1111.     break;
  1112.       
  1113.       if (zone_table[zon].cmd[cmd_no].command == '*')    {
  1114.     expand = 0;
  1115.     fgets(buf, 80, fl); /* skip command */
  1116.     continue;
  1117.       }
  1118.       
  1119.       fscanf(fl, " %d %d %d", 
  1120.          &tmp,
  1121.          &zone_table[zon].cmd[cmd_no].arg1,
  1122.          &zone_table[zon].cmd[cmd_no].arg2);
  1123.       
  1124.       zone_table[zon].cmd[cmd_no].if_flag = tmp;
  1125.       
  1126.       if (zone_table[zon].cmd[cmd_no].command == 'M' ||
  1127.       zone_table[zon].cmd[cmd_no].command == 'O' ||
  1128.       zone_table[zon].cmd[cmd_no].command == 'C' ||
  1129.       zone_table[zon].cmd[cmd_no].command == 'E' ||
  1130.       zone_table[zon].cmd[cmd_no].command == 'P' ||
  1131.       zone_table[zon].cmd[cmd_no].command == 'D')
  1132.     fscanf(fl, " %d", &zone_table[zon].cmd[cmd_no].arg3);
  1133.       
  1134.       fgets(buf, 80, fl);    /* read comment */
  1135.       cmd_no++;
  1136.     }
  1137.     zon++;
  1138.     if (zon == 1) {
  1139.       /* fix the cheat */
  1140. /*      if (fl != tmp_fl && fl != 0)
  1141.     fclose(fl);
  1142.       fl = tmp_fl;*/
  1143.     }
  1144.  
  1145.   }
  1146.   top_of_zone_table = --zon;
  1147.   free(check);
  1148.   fclose(fl);
  1149. }
  1150.  
  1151.  
  1152. /*************************************************************************
  1153. *  procedures for resetting, both play-time and boot-time          *
  1154. *********************************************************************** */
  1155.  
  1156.  
  1157. /* read a mobile from MOB_FILE */
  1158. struct char_data *read_mobile(int nr, int type)
  1159. {
  1160.   int i;
  1161.   long tmp, tmp2, tmp3, bc=0;
  1162.   struct char_data *mob;
  1163.   char buf[100], buffer[255];
  1164.   char letter;
  1165.  
  1166.   extern int mob_tick_count;
  1167.   extern long mob_count;
  1168.   
  1169.   i = nr;
  1170.   if (type == VIRTUAL)
  1171.     if ((nr = real_mobile(nr)) < 0)    {
  1172.       sprintf(buf, "Mobile (V) %d does not exist in database.", i);
  1173.       return(0);
  1174.     }
  1175.   
  1176.   fseek(mob_f, mob_index[nr].pos, 0);
  1177.   
  1178.   CREATE(mob, struct char_data, 1);
  1179.   bc = sizeof(struct char_data);
  1180.   clear_char(mob);
  1181.   
  1182.   /***** String data *** */
  1183.   
  1184.   mob->player.name = fread_string(mob_f);
  1185.   if (*mob->player.name)
  1186.     bc += strlen(mob->player.name);
  1187.   mob->player.short_descr = fread_string(mob_f);
  1188.   if (*mob->player.short_descr)
  1189.     bc += strlen(mob->player.short_descr);
  1190.   mob->player.long_descr = fread_string(mob_f);
  1191.   if (*mob->player.long_descr)
  1192.     bc += strlen(mob->player.long_descr);
  1193.   mob->player.description = fread_string(mob_f);
  1194.   if (mob->player.description && *mob->player.description)
  1195.     bc += strlen(mob->player.description);
  1196.   mob->player.title = 0;
  1197.   
  1198.   /* *** Numeric data *** */
  1199.   
  1200.   mob->mult_att = 1.0;
  1201.   mob->specials.spellfail = 101;
  1202.   
  1203.   fscanf(mob_f, "%d ", &tmp);
  1204.   mob->specials.act = tmp;
  1205.   SET_BIT(mob->specials.act, ACT_ISNPC);
  1206.   
  1207.   fscanf(mob_f, " %d ", &tmp);
  1208.   mob->specials.affected_by = tmp;
  1209.   
  1210.   fscanf(mob_f, " %d ", &tmp);
  1211.   mob->specials.alignment = tmp;
  1212.  
  1213.   mob->player.class = CLASS_WARRIOR;
  1214.   
  1215.   fscanf(mob_f, " %c ", &letter);
  1216.   
  1217.   if (letter == 'S') {
  1218.     
  1219.     fscanf(mob_f, "\n");
  1220.     
  1221.     /* The new easy monsters */
  1222.     mob->abilities.str   = 11;
  1223.     mob->abilities.intel = 11; 
  1224.     mob->abilities.wis   = 11;
  1225.     mob->abilities.dex   = 11;
  1226.     mob->abilities.con   = 11;
  1227.     mob->abilities.chr   = 11;
  1228.     
  1229.     fscanf(mob_f, " %D ", &tmp);
  1230.     GET_LEVEL(mob, WARRIOR_LEVEL_IND) = tmp;
  1231.  
  1232.     fscanf(mob_f, " %D ", &tmp);
  1233.     mob->points.hitroll = 20-tmp;
  1234.     
  1235.     fscanf(mob_f, " %D ", &tmp);
  1236.  
  1237.     if (tmp > 10 || tmp < -10)
  1238.       tmp /= 10;
  1239.  
  1240.     mob->points.armor = 10*tmp;
  1241.     
  1242.     fscanf(mob_f, " %Dd%D+%D ", &tmp, &tmp2, &tmp3);
  1243.     mob->points.max_hit = dice(tmp, tmp2)+tmp3;
  1244.     mob->points.hit = mob->points.max_hit;
  1245.     
  1246.     fscanf(mob_f, " %Dd%D+%D \n", &tmp, &tmp2, &tmp3);
  1247.     mob->points.damroll = tmp3;
  1248.     mob->specials.damnodice = tmp;
  1249.     mob->specials.damsizedice = tmp2;
  1250.     
  1251.     mob->points.mana = 10;
  1252.     mob->points.max_mana = 10;   
  1253.     
  1254.     
  1255.     mob->points.move = 50;
  1256.     mob->points.max_move = 50;
  1257.     
  1258.     fscanf(mob_f, " %D ", &tmp);
  1259.     if (tmp == -1) {
  1260.       fscanf(mob_f, " %D ", &tmp);
  1261.       mob->points.gold = tmp;
  1262.       fscanf(mob_f, " %D ", &tmp);
  1263.       GET_EXP(mob) = tmp;
  1264.       fscanf(mob_f, " %D \n", &tmp);
  1265.       GET_RACE(mob) = tmp;
  1266.     } else {
  1267.       mob->points.gold = tmp;
  1268.       fscanf(mob_f, " %D \n", &tmp);
  1269.       GET_EXP(mob) = tmp;
  1270.     }
  1271.     fscanf(mob_f, " %D ", &tmp);
  1272.     mob->specials.position = tmp;
  1273.     
  1274.     fscanf(mob_f, " %D ", &tmp);
  1275.     mob->specials.default_pos = tmp;
  1276.     
  1277.     fscanf(mob_f, " %D ", &tmp);
  1278.     if (tmp < 3) {
  1279.       mob->player.sex = tmp;
  1280.       mob->immune = 0;
  1281.       mob->M_immune = 0;
  1282.       mob->susc = 0;
  1283.     } else if (tmp < 6) {
  1284.       mob->player.sex = (tmp-3);
  1285.       fscanf(mob_f, " %D ", &tmp);
  1286.       mob->immune = tmp;
  1287.       fscanf(mob_f, " %D ", &tmp);
  1288.       mob->M_immune = tmp;
  1289.       fscanf(mob_f, " %D ", &tmp);
  1290.       mob->susc = tmp;
  1291.     } else {
  1292.       mob->player.sex = 0;
  1293.       mob->immune = 0;
  1294.       mob->M_immune = 0;
  1295.       mob->susc = 0;
  1296.     }
  1297.     
  1298.     fscanf(mob_f,"\n");
  1299.     
  1300.     mob->player.class = 0;
  1301.     
  1302.     mob->player.time.birth = time(0);
  1303.     mob->player.time.played    = 0;
  1304.     mob->player.time.logon  = time(0);
  1305.     mob->player.weight = 200;
  1306.     mob->player.height = 198;
  1307.     
  1308.     for (i = 0; i < 3; i++)
  1309.       GET_COND(mob, i) = -1;
  1310.     
  1311.     for (i = 0; i < 5; i++)
  1312.       mob->specials.apply_saving_throw[i] = MAX(20-GET_LEVEL(mob, WARRIOR_LEVEL_IND), 2);
  1313.     
  1314.   } else if ((letter == 'A') || (letter == 'N') || (letter == 'B') ||
  1315.          (letter == 'L')) {
  1316.     
  1317.     if ((letter == 'A') || (letter == 'B') || (letter == 'L')) {
  1318.       fscanf(mob_f, " %D ", &tmp);
  1319.       mob->mult_att = (float)tmp;
  1320.       /*
  1321.       **  read in types:
  1322.       */
  1323.       /*
  1324.     for (i=0;i<mob->mult_att && i < 10; i++) {
  1325.        fscanf(mob_f, " %D ", &tmp);
  1326.        mob->att_type[i] = tmp;
  1327.     }
  1328.       */
  1329.     }
  1330.     
  1331.     fscanf(mob_f, "\n");
  1332.     
  1333.     /* The new easy monsters */
  1334.     mob->abilities.str   = 11;
  1335.     mob->abilities.intel = 11; 
  1336.     mob->abilities.wis   = 11;
  1337.     mob->abilities.dex   = 11;
  1338.     mob->abilities.con   = 11;
  1339.     mob->abilities.chr   = 11;
  1340.     
  1341.     fscanf(mob_f, " %D ", &tmp);
  1342.     GET_LEVEL(mob, WARRIOR_LEVEL_IND) = tmp;
  1343.     
  1344.     fscanf(mob_f, " %D ", &tmp);
  1345.     mob->points.hitroll = 20-tmp;
  1346.     
  1347.     fscanf(mob_f, " %D ", &tmp);
  1348.     mob->points.armor = 10*tmp;
  1349.     fscanf(mob_f, " %D ", &tmp);
  1350.     mob->points.max_hit = dice(GET_LEVEL(mob, WARRIOR_LEVEL_IND), 8)+tmp;
  1351.     mob->points.hit = mob->points.max_hit;
  1352.     
  1353.     fscanf(mob_f, " %Dd%D+%D \n", &tmp, &tmp2, &tmp3);
  1354.     mob->points.damroll = tmp3;
  1355.     mob->specials.damnodice = tmp;
  1356.     mob->specials.damsizedice = tmp2;
  1357.     
  1358.     mob->points.mana = 10;
  1359.     mob->points.max_mana = 10;   
  1360.     
  1361.     
  1362.     mob->points.move = 50;
  1363.     mob->points.max_move = 50;
  1364.     
  1365.     fscanf(mob_f, " %D ", &tmp);
  1366.     
  1367.     if (tmp == -1) {
  1368.       fscanf(mob_f, " %D ", &tmp);
  1369.       mob->points.gold = tmp;
  1370.       fscanf(mob_f, " %D ", &tmp);
  1371.       if (tmp >= 0)
  1372.     GET_EXP(mob) = (DetermineExp(mob, tmp)+mob->points.gold);
  1373.       else 
  1374.     GET_EXP(mob) = -tmp;
  1375.       fscanf(mob_f, " %D ", &tmp);
  1376.       GET_RACE(mob) = tmp;
  1377.       
  1378.     } else {
  1379.       mob->points.gold = tmp;
  1380.       
  1381.       /*
  1382.     this is where the new exp will come into play
  1383.     */
  1384.       fscanf(mob_f, " %D \n", &tmp);
  1385.       GET_EXP(mob) = (DetermineExp(mob, tmp)+mob->points.gold);
  1386.     }
  1387.  
  1388.     fscanf(mob_f, " %D ", &tmp);
  1389.     mob->specials.position = tmp;
  1390.     
  1391.     fscanf(mob_f, " %D ", &tmp);
  1392.     mob->specials.default_pos = tmp;
  1393.     
  1394.     fscanf(mob_f, " %D \n", &tmp);
  1395.     if (tmp < 3) {
  1396.       mob->player.sex = tmp;
  1397.       mob->immune = 0;
  1398.       mob->M_immune = 0;
  1399.       mob->susc = 0;
  1400.     } else if (tmp < 6) {
  1401.       mob->player.sex = (tmp-3);
  1402.       fscanf(mob_f, " %D ", &tmp);
  1403.       mob->immune = tmp;
  1404.       fscanf(mob_f, " %D ", &tmp);
  1405.       mob->M_immune = tmp;
  1406.       fscanf(mob_f, " %D ", &tmp);
  1407.       mob->susc = tmp;
  1408.     } else {
  1409.       mob->player.sex = 0;
  1410.       mob->immune = 0;
  1411.       mob->M_immune = 0;
  1412.       mob->susc = 0;
  1413.     }
  1414.  
  1415.     /*
  1416.      *   read in the sound string for a mobile
  1417.      */
  1418.     if (letter == 'L') {
  1419.        mob->player.sounds = fread_string(mob_f);
  1420.        if (mob->player.sounds && *mob->player.sounds)
  1421.            bc += strlen(mob->player.sounds);
  1422.  
  1423.        mob->player.distant_snds = fread_string(mob_f);
  1424.        if (mob->player.distant_snds && *mob->player.distant_snds)
  1425.            bc += strlen(mob->player.distant_snds);
  1426.     } else {
  1427.       mob->player.sounds = 0;
  1428.       mob->player.distant_snds = 0;
  1429.     }
  1430.  
  1431.     if (letter == 'B') {
  1432.       SET_BIT(mob->specials.act, ACT_HUGE);
  1433.     }
  1434.  
  1435.     mob->player.class = 0;
  1436.     
  1437.     mob->player.time.birth = time(0);
  1438.     mob->player.time.played    = 0;
  1439.     mob->player.time.logon  = time(0);
  1440.     mob->player.weight = 200;
  1441.     mob->player.height = 198;
  1442.     
  1443.     for (i = 0; i < 3; i++)
  1444.       GET_COND(mob, i) = -1;
  1445.     
  1446.     for (i = 0; i < 5; i++)
  1447.       mob->specials.apply_saving_throw[i] = MAX(20-GET_LEVEL(mob, WARRIOR_LEVEL_IND), 2);
  1448.     
  1449.   } else {  /* The old monsters are down below here */
  1450.     
  1451.     fscanf(mob_f, "\n");
  1452.     
  1453.     fscanf(mob_f, " %D ", &tmp);
  1454.     mob->abilities.str = tmp;
  1455.     
  1456.     fscanf(mob_f, " %D ", &tmp);
  1457.     mob->abilities.intel = tmp; 
  1458.     
  1459.     fscanf(mob_f, " %D ", &tmp);
  1460.     mob->abilities.wis = tmp;
  1461.     
  1462.     fscanf(mob_f, " %D ", &tmp);
  1463.     mob->abilities.dex = tmp;
  1464.     
  1465.     fscanf(mob_f, " %D \n", &tmp);
  1466.     mob->abilities.con = tmp;
  1467.     
  1468.     fscanf(mob_f, " %D ", &tmp);
  1469.     fscanf(mob_f, " %D ", &tmp2);
  1470.     
  1471.     mob->points.max_hit = number(tmp, tmp2);
  1472.     mob->points.hit = mob->points.max_hit;
  1473.     
  1474.     fscanf(mob_f, " %D ", &tmp);
  1475.     mob->points.armor = 10*tmp;
  1476.     
  1477.     fscanf(mob_f, " %D ", &tmp);
  1478.     mob->points.mana = tmp;
  1479.     mob->points.max_mana = tmp;
  1480.     
  1481.     fscanf(mob_f, " %D ", &tmp);
  1482.     mob->points.move = tmp;        
  1483.     mob->points.max_move = tmp;
  1484.     
  1485.     fscanf(mob_f, " %D ", &tmp);
  1486.     mob->points.gold = tmp;
  1487.     
  1488.     fscanf(mob_f, " %D \n", &tmp);
  1489.     GET_EXP(mob) = tmp;
  1490.     
  1491.     fscanf(mob_f, " %D ", &tmp);
  1492.     mob->specials.position = tmp;
  1493.     
  1494.     fscanf(mob_f, " %D ", &tmp);
  1495.     mob->specials.default_pos = tmp;
  1496.     
  1497.     fscanf(mob_f, " %D ", &tmp);
  1498.     mob->player.sex = tmp;
  1499.     
  1500.     fscanf(mob_f, " %D ", &tmp);
  1501.     mob->player.class = tmp;
  1502.     
  1503.     fscanf(mob_f, " %D ", &tmp);
  1504.     GET_LEVEL(mob, WARRIOR_LEVEL_IND) = tmp;
  1505.     
  1506.     fscanf(mob_f, " %D ", &tmp);
  1507.     mob->player.time.birth = time(0);
  1508.     mob->player.time.played    = 0;
  1509.     mob->player.time.logon  = time(0);
  1510.     
  1511.     fscanf(mob_f, " %D ", &tmp);
  1512.     mob->player.weight = tmp;
  1513.     
  1514.     fscanf(mob_f, " %D \n", &tmp);
  1515.     mob->player.height = tmp;
  1516.     
  1517.     for (i = 0; i < 3; i++)
  1518.       {
  1519.     fscanf(mob_f, " %D ", &tmp);
  1520.     GET_COND(mob, i) = tmp;
  1521.       }
  1522.     fscanf(mob_f, " \n ");
  1523.     
  1524.     for (i = 0; i < 5; i++)
  1525.       {
  1526.     fscanf(mob_f, " %D ", &tmp);
  1527.     mob->specials.apply_saving_throw[i] = tmp;
  1528.       }
  1529.     
  1530.     fscanf(mob_f, " \n ");
  1531.     
  1532.     /* Set the damage as some standard 1d4 */
  1533.     mob->points.damroll = 0;
  1534.     mob->specials.damnodice = 1;
  1535.     mob->specials.damsizedice = 6;
  1536.     
  1537.     /* Calculate THAC0 as a formular of Level */
  1538.     mob->points.hitroll = MAX(1, GET_LEVEL(mob,WARRIOR_LEVEL_IND)-3);
  1539.   }
  1540.   
  1541.   mob->tmpabilities = mob->abilities;
  1542.   
  1543.   for (i = 0; i < MAX_WEAR; i++) /* Initialisering Ok */
  1544.     mob->equipment[i] = 0;
  1545.   
  1546.   mob->nr = nr;
  1547.   
  1548.   mob->desc = 0;
  1549.   
  1550.   if (!IS_SET(mob->specials.act, ACT_ISNPC))
  1551.     SET_BIT(mob->specials.act, ACT_ISNPC);
  1552.   
  1553.   mob->generic = 0;
  1554.   mob->commandp = 0;
  1555.   mob->commandp2 = 0;
  1556.   mob->waitp = 0;
  1557.  
  1558.   /* Check to see if associated with a script, if so, set it up */
  1559.   if(IS_SET(mob->specials.act, ACT_SCRIPT))
  1560.      REMOVE_BIT(mob->specials.act, ACT_SCRIPT);
  1561.  
  1562.   for(i = 0; i < top_of_scripts; i++) {
  1563.  
  1564.     if(script_data[i].virtual == mob_index[nr].virtual) {
  1565.        SET_BIT(mob->specials.act, ACT_SCRIPT);
  1566. /*       sprintf(buffer, "Setting SCRIPT bit for mobile %s, file %s.", GET_NAME(mob), script_data[i].filename);
  1567.        log(buffer); */
  1568.        mob->script = i;
  1569.        break;
  1570.   }
  1571. }     
  1572.   /* tell the spec_proc (if there is one) that we've been born */
  1573. /*  if(mob_index[nr].func)
  1574.     (*mob_index[nr].func)(mob, 0, "", mob, EVENT_BIRTH);
  1575. */  
  1576.   /* insert in list */
  1577.   
  1578.   mob->next = character_list;
  1579.   character_list = mob;
  1580.  
  1581. #if NEW_RENT
  1582.   if (mob->points.gold >= 10)
  1583.     mob->points.gold /= 10;
  1584.   else if (mob->points.gold > 0)
  1585.     mob->points.gold = 1;
  1586. #endif
  1587.  
  1588.   if (mob->points.gold > GET_LEVEL(mob, WARRIOR_LEVEL_IND)*1500) {
  1589.     char buf[200];
  1590.     sprintf(buf, "%s has gold > level * 1500 (%d)", mob->player.short_descr,
  1591.         mob->points.gold);
  1592.     log(buf);
  1593.   }
  1594.  
  1595.   /* set up things that all members of the race have */
  1596.   SetRacialStuff(mob);
  1597.  
  1598.   /* change exp for wimpy mobs (lower) */
  1599.   if (IS_SET(mob->specials.act, ACT_WIMPY))
  1600.     GET_EXP(mob) -= GET_EXP(mob)/10;
  1601.     
  1602.   /* change exp for agressive mobs (higher) */
  1603.   if (IS_SET(mob->specials.act, ACT_AGGRESSIVE)) {
  1604.       GET_EXP(mob) += GET_EXP(mob)/10;
  1605. /* big bonus for fully aggressive mobs for now */
  1606.       if (!IS_SET(mob->specials.act, ACT_WIMPY)||
  1607.       IS_SET(mob->specials.act, ACT_META_AGG))
  1608.     GET_EXP(mob) += (GET_EXP(mob)/2);
  1609.   }
  1610.  
  1611.   /* set up distributed movement system */
  1612.     
  1613.   mob->specials.tick = mob_tick_count++;
  1614.  
  1615.   if (mob_tick_count == TICK_WRAP_COUNT)
  1616.     mob_tick_count=0;
  1617.   
  1618.   mob_index[nr].number++;
  1619.  
  1620. #if BYTE_COUNT
  1621.   fprintf(stderr,"Mobile [%d]: byte count: %d\n", mob_index[nr].virtual, bc);
  1622. #endif
  1623.  
  1624.   total_mbc += bc;
  1625.   mob_count++;  
  1626.   return(mob);
  1627. }
  1628.  
  1629.  
  1630. /* read an object from OBJ_FILE */
  1631. struct obj_data *read_object(int nr, int type)
  1632. {
  1633.   struct obj_data *obj;
  1634.   int tmp, i;
  1635.   long bc;
  1636.   char chk[50], buf[100];
  1637.   struct extra_descr_data *new_descr;
  1638.  
  1639.   extern long obj_count;
  1640.   extern long total_obc;
  1641.   
  1642.   i = nr;
  1643.   if (type == VIRTUAL) {
  1644.     nr = real_object(nr);
  1645.   }
  1646.   if (nr<0 || nr>top_of_objt) {
  1647.     sprintf(buf, "Object (V) %d does not exist in database.", i);
  1648.     return(0);
  1649.   }
  1650.   
  1651.   fseek(obj_f, obj_index[nr].pos, 0);
  1652.   
  1653.   CREATE(obj, struct obj_data, 1);
  1654.   bc = sizeof(struct obj_data);
  1655.     
  1656.   clear_object(obj);
  1657.   
  1658.   /* *** string data *** */
  1659.   
  1660.   obj->name = fread_string(obj_f);
  1661.   if (obj->name && *obj->name) {
  1662.     bc += strlen(obj->name);
  1663.   }
  1664.   obj->short_description = fread_string(obj_f);
  1665.   if (obj->short_description && *obj->short_description) {
  1666.     bc += strlen(obj->short_description);
  1667.   }
  1668.   obj->description = fread_string(obj_f);
  1669.   if (obj->description && *obj->description) {
  1670.     bc += strlen(obj->description);
  1671.   }
  1672.   obj->action_description = fread_string(obj_f);
  1673.   if (obj->action_description && *obj->action_description) {
  1674.     bc += strlen(obj->action_description);
  1675.   }
  1676.   
  1677.   /* *** numeric data *** */
  1678.   
  1679.   fscanf(obj_f, " %d ", &tmp);
  1680.   obj->obj_flags.type_flag = tmp;
  1681.   fscanf(obj_f, " %d ", &tmp);
  1682.   obj->obj_flags.extra_flags = tmp;
  1683.   fscanf(obj_f, " %d ", &tmp);
  1684.   obj->obj_flags.wear_flags = tmp;
  1685.   fscanf(obj_f, " %d ", &tmp);
  1686.   obj->obj_flags.value[0] = tmp;
  1687.   fscanf(obj_f, " %d ", &tmp);
  1688.   obj->obj_flags.value[1] = tmp;
  1689.   fscanf(obj_f, " %d ", &tmp);
  1690.   obj->obj_flags.value[2] = tmp;
  1691.   fscanf(obj_f, " %d ", &tmp);
  1692.   obj->obj_flags.value[3] = tmp;
  1693.   fscanf(obj_f, " %d ", &tmp);
  1694.   obj->obj_flags.weight = tmp;
  1695.   fscanf(obj_f, " %d \n", &tmp);
  1696.   obj->obj_flags.cost = tmp;
  1697.   fscanf(obj_f, " %d \n", &tmp);
  1698.   obj->obj_flags.cost_per_day = tmp;
  1699.   
  1700.   /* *** extra descriptions *** */
  1701.   
  1702.   obj->ex_description = 0;
  1703.   
  1704.   while (fscanf(obj_f, " %s \n", chk), *chk == 'E')    {
  1705.     CREATE(new_descr, struct extra_descr_data, 1);
  1706.     bc += sizeof(struct extra_descr_data);
  1707.     new_descr->keyword = fread_string(obj_f);
  1708.     if (new_descr->keyword && *new_descr->keyword)
  1709.       bc += strlen(new_descr->keyword);
  1710.     new_descr->description = fread_string(obj_f);
  1711.     if (new_descr->description && *new_descr->description)
  1712.       bc += strlen(new_descr->description);
  1713.     
  1714.     new_descr->next = obj->ex_description;
  1715.     obj->ex_description = new_descr;
  1716.   }
  1717.   
  1718.   for( i = 0 ; (i < MAX_OBJ_AFFECT) && (*chk == 'A') ; i++)    {
  1719.     fscanf(obj_f, " %d ", &tmp);
  1720.     obj->affected[i].location = tmp;
  1721.     fscanf(obj_f, " %d \n", &tmp);
  1722.     obj->affected[i].modifier = tmp;
  1723.     fscanf(obj_f, " %s \n", chk);
  1724.   }
  1725.   
  1726.   for (;(i < MAX_OBJ_AFFECT);i++)    {
  1727.     obj->affected[i].location = APPLY_NONE;
  1728.     obj->affected[i].modifier = 0;
  1729.   }
  1730.   
  1731.   obj->in_room = NOWHERE;
  1732.   obj->next_content = 0;
  1733.   obj->carried_by = 0;
  1734.   obj->equipped_by = 0;
  1735.   obj->eq_pos = -1;
  1736.   obj->in_obj = 0;
  1737.   obj->contains = 0;
  1738.   obj->item_number = nr;    
  1739.   obj->in_obj = 0;
  1740.   
  1741.   obj->next = object_list;
  1742.   object_list = obj;
  1743.   
  1744.   obj_index[nr].number++;
  1745.  
  1746.  
  1747.   obj_count++;  
  1748. #if BYTE_COUNT
  1749.   fprintf(stderr, "Object [%d] uses %d bytes\n", obj_index[nr].virtual, bc);
  1750. #endif
  1751.   total_obc += bc;
  1752.   return (obj);  
  1753. }
  1754.  
  1755.  
  1756.  
  1757.  
  1758. #define ZO_DEAD  999
  1759.  
  1760. /* update zone ages, queue for reset if necessary, and dequeue when possible */
  1761. void zone_update()
  1762. {
  1763.   int i;
  1764.   struct reset_q_element *update_u, *temp, *tmp2;
  1765.   extern struct reset_q_type reset_q;
  1766.   
  1767.   
  1768.   /* enqueue zones */
  1769.   
  1770.   for (i = 0; i <= top_of_zone_table; i++)    {
  1771.     if (zone_table[i].start) {
  1772.       if (zone_table[i].age < zone_table[i].lifespan &&
  1773.       zone_table[i].reset_mode)
  1774.     (zone_table[i].age)++;
  1775.       else
  1776.     if (zone_table[i].age < ZO_DEAD && zone_table[i].reset_mode)    {
  1777.       /* enqueue zone */
  1778.       
  1779.       CREATE(update_u, struct reset_q_element, 1);
  1780.       
  1781.       update_u->zone_to_reset = i;
  1782.       update_u->next = 0;
  1783.     
  1784.       if (!reset_q.head)
  1785.         reset_q.head = reset_q.tail = update_u;
  1786.       else  {
  1787.         reset_q.tail->next = update_u;
  1788.         reset_q.tail = update_u;
  1789.       }
  1790.       
  1791.       zone_table[i].age = ZO_DEAD;
  1792.     }
  1793.     }
  1794.   }
  1795.     
  1796.   /* dequeue zones (if possible) and reset */
  1797.   
  1798.   for (update_u = reset_q.head; update_u; update_u = tmp2) {
  1799.     if (update_u->zone_to_reset > top_of_zone_table) {
  1800.       
  1801.       /*  this may or may not work */
  1802.       /*  may result in some lost memory, but the loss is not signifigant
  1803.       over the short run
  1804.       */
  1805.       update_u->zone_to_reset = 0;
  1806.       update_u->next = 0;
  1807.     }
  1808.     tmp2 = update_u->next;
  1809.  
  1810.     if (IS_SET(zone_table[update_u->zone_to_reset].reset_mode, ZONE_ALWAYS) ||
  1811.        (IS_SET(zone_table[update_u->zone_to_reset].reset_mode, ZONE_EMPTY) &&
  1812.            is_empty(update_u->zone_to_reset))) {
  1813.       reset_zone(update_u->zone_to_reset);
  1814.       /* dequeue */
  1815.       
  1816.       if (update_u == reset_q.head)
  1817.     reset_q.head = reset_q.head->next;
  1818.       else {
  1819.     for (temp = reset_q.head; temp->next != update_u; temp = temp->next)
  1820.       ;
  1821.  
  1822.     if (!update_u->next) 
  1823.       reset_q.tail = temp;
  1824.  
  1825.     temp->next = update_u->next;
  1826.       }
  1827.       free(update_u);
  1828.     }
  1829.   }
  1830. }
  1831.  
  1832.  
  1833.  
  1834.  
  1835. #define ZCMD zone_table[zone].cmd[cmd_no]
  1836.  
  1837. /* execute the reset command table of a given zone */
  1838. void reset_zone(int zone)
  1839. {
  1840.   int cmd_no, last_cmd = 1, j;
  1841.   char buf[256];
  1842.   struct char_data *mob;
  1843.   struct char_data *master;
  1844.   struct obj_data *obj, *obj_to;
  1845.   struct room_data    *rp;
  1846.   FILE *fl;
  1847.   static int done = 0;
  1848.  
  1849.   mob = 0;
  1850.  
  1851.  
  1852.   if (zone == 0 && !done) {
  1853.     int count = 0;
  1854.     done = 1;
  1855.  
  1856.     fl = fopen("world/mobs", "r");
  1857.     if(!fl) {
  1858.       log("Unable to load scratch zone file for update.");
  1859.        return;
  1860.     }
  1861.     while (1){
  1862.       char c, buf[255];
  1863.       int i, j, k, tmp;
  1864.  
  1865.       count++;
  1866.       /*fprintf(stderr, "%d ", count);*/
  1867.       fscanf(fl, " "); /* skip blanks */
  1868.       fscanf(fl, "%c", &c);
  1869.  
  1870.       
  1871.       if (c == 'S' || c == EOF)
  1872.     break;
  1873.       
  1874.       if (c == '*'){
  1875.     fgets(buf, 80, fl); /* skip command */
  1876.     continue;
  1877.       }
  1878.       
  1879.       fscanf(fl, " %d %d %d", &tmp, &i, &j);
  1880.       if (c == 'M' || c == 'O' || c == 'C' || c == 'E' || c == 'P' || c == 'D')
  1881.     fscanf(fl, " %d", &k);
  1882.       
  1883.       fgets(buf, 80, fl);/* read comment */
  1884.       if(last_cmd || tmp <= 0)
  1885.       switch(c) {
  1886.       case 'M': /* read a mobile */
  1887.     i = real_mobile(i);
  1888.     if ((mob_index[i].number < j) && !CheckKillFile(mob_index[i].virtual)) {
  1889.         mob = read_mobile(i, REAL);
  1890.         char_to_room(mob, k);
  1891.  
  1892.         last_cmd = 1;
  1893.         master = mob;
  1894.       } else
  1895.         last_cmd = 0;
  1896.     break;
  1897.  
  1898.       case 'C': /* read a mobile.  Charm them to follow prev. */
  1899.     i = real_mobile(i);
  1900.     if ((mob_index[i].number < j) && !CheckKillFile(mob_index[i].virtual)){
  1901.       mob = read_mobile(i, REAL);
  1902.       if (master) {
  1903.         char_to_room(mob, master->in_room);
  1904.         /*
  1905.           add the charm bit to the dude.
  1906.           */
  1907.         add_follower(mob, master);
  1908.         SET_BIT(mob->specials.affected_by, AFF_CHARM);
  1909.         SET_BIT(mob->specials.act, k);
  1910.       } else {
  1911.         extract_char(mob);
  1912.         last_cmd = 0;
  1913.       }
  1914.       last_cmd = 1;
  1915.     }
  1916.     else
  1917.       last_cmd = 0;
  1918.     break;
  1919.  
  1920.       case 'Z':  /* set the last mobile to this zone */
  1921.     if (mob) {
  1922.       mob->specials.zone =i;
  1923.       
  1924.       if (GET_RACE(mob)>RACE_GNOME)
  1925.         if (!strchr(zone_table[i].races, GET_RACE(mob))) {
  1926.           zone_table[i].races[strlen(zone_table[i].races)] = 
  1927.         GET_RACE(mob);
  1928.         }
  1929.       last_cmd = 1;
  1930.     } else {      
  1931.       last_cmd = 0;
  1932.     }
  1933.         break;
  1934.     
  1935.       case 'O': /* read an object */
  1936.     i = real_object(i);
  1937.     if (obj_index[i].number < j) {
  1938.       if (j >= 0 && ((rp = real_roomp(j)) != NULL)) {
  1939.         if((tmp>0&&ObjRoomCount(i,rp)<tmp) ||
  1940.            (tmp<=0&&ObjRoomCount(i,rp)<(-tmp)+1)){
  1941.           if ((obj = read_object(i, REAL)) != NULL) {
  1942.         obj_to_room(obj, k);
  1943.         last_cmd = 1;
  1944.           } else {
  1945.         last_cmd = 0;
  1946.           }
  1947.         } else {
  1948.           last_cmd = 0;
  1949.         }
  1950.       } else if (obj = read_object(i, VIRTUAL)) {
  1951.         sprintf(buf, "Error finding room #%d", k);
  1952.         log(buf);
  1953.         last_cmd = 1;
  1954.       }  else {
  1955.         last_cmd = 0;
  1956.       }
  1957.     }
  1958.     break;
  1959.     
  1960.       case 'P': /* object to object */
  1961.     i = real_object(i);
  1962.     if (obj_index[i].number < j)  {
  1963.       obj = read_object(i, VIRTUAL);
  1964.       obj_to = get_obj_num(k);
  1965.       if (obj_to && obj) {
  1966.         obj_to_obj(obj, obj_to);
  1967.         last_cmd = 1;
  1968.       } else {
  1969.         last_cmd = 0;
  1970.       }
  1971.     } else
  1972.       last_cmd = 0;
  1973.     break;
  1974.     
  1975.       case 'G': /* obj_to_char */
  1976.     i = real_object(i);
  1977.     if (obj_index[i].number < j &&
  1978.         (obj = read_object(i, REAL))) {
  1979.       obj_to_char(obj, mob);
  1980.       last_cmd = 1;
  1981. #ifndef NEW_RENT
  1982.     } else {
  1983.       last_cmd = 0;
  1984. #endif
  1985.     }
  1986.     break;
  1987.     
  1988.       case 'H': /* hatred to char */
  1989.     
  1990.     if (AddHatred(mob, i, j))
  1991.         last_cmd = 1;
  1992.     else 
  1993.         last_cmd = 0;
  1994.     break;
  1995.     
  1996.       case 'F': /* fear to char */
  1997.     
  1998.     if (AddFears(mob, i, j))
  1999.         last_cmd = 1;
  2000.     else 
  2001.         last_cmd = 0;
  2002.     break;
  2003.     
  2004.       case 'E': /* object to equipment list */
  2005.     i = real_object(i);
  2006.     if (obj_index[i].number < j &&
  2007.         (obj = read_object(i, REAL))) {
  2008.       if (!mob->equipment[k]) {
  2009.         equip_char(mob, obj, k);
  2010.       } else {
  2011.         sprintf(buf,"eq error - zone %d, cmd %d, item %d, mob %d, loc %d", 
  2012.             zone, 1, obj_index[i].virtual, 
  2013.             mob_index[mob->nr].virtual, k);
  2014.         log_sev(buf, 6);
  2015.       }
  2016.       last_cmd = 1;
  2017.     }    else
  2018.       last_cmd = 0;
  2019.     break;
  2020.     
  2021.       case 'D': /* set state of door */
  2022.     rp = real_roomp(i);
  2023.     if (rp && rp->dir_option[j]) {
  2024.         switch (k) {
  2025.         case 0:
  2026.               REMOVE_BIT(rp->dir_option[j]->exit_info, EX_LOCKED);
  2027.               REMOVE_BIT(rp->dir_option[j]->exit_info, EX_CLOSED);
  2028.               break;
  2029.         case 1:
  2030.               SET_BIT(rp->dir_option[j]->exit_info, EX_CLOSED);
  2031.               REMOVE_BIT(rp->dir_option[j]->exit_info, EX_LOCKED);
  2032.               break;
  2033.         case 2:
  2034.               SET_BIT(rp->dir_option[j]->exit_info, EX_LOCKED);
  2035.               SET_BIT(rp->dir_option[j]->exit_info, EX_CLOSED);
  2036.               break;
  2037.         }
  2038.           last_cmd = 1;
  2039.       } else {
  2040.           /* that exit doesn't exist anymore */
  2041.       }
  2042.     break;
  2043.       
  2044.       default:
  2045.     break;
  2046.       }
  2047.     }
  2048.   return;
  2049.   }
  2050.  
  2051.  
  2052.   if (zone_table[zone].start == 0) {
  2053.     char    *s;
  2054.     int    d,e;
  2055.     s = zone_table[zone].name;
  2056.     d = (zone ? (zone_table[zone - 1].top + 1) : 0);
  2057.     e = zone_table[zone].top;
  2058.     sprintf(buf, "Run time initialization of zone %s, rooms (%d-%d)",
  2059.         s, d, e);
  2060.     log(buf);
  2061.  
  2062.   }
  2063.  
  2064.   if (!zone_table[zone].cmd) {
  2065.     return;
  2066.   } 
  2067.   
  2068.   for (cmd_no = 0;;cmd_no++) {
  2069.     if (ZCMD.command == 'S')
  2070.       break;
  2071.       
  2072.     if (last_cmd || ZCMD.if_flag <= 0)
  2073.       switch(ZCMD.command) {
  2074.       case 'M': /* read a mobile */
  2075.     if ((mob_index[ZCMD.arg1].number < ZCMD.arg2) && !CheckKillFile(mob_index[ZCMD.arg1].virtual)) {
  2076.       mob = read_mobile(ZCMD.arg1, REAL);
  2077.       mob->specials.zone = zone;
  2078.       char_to_room(mob, ZCMD.arg3);
  2079.  
  2080.       if (GET_RACE(mob)>RACE_GNOME)
  2081.         if (!strchr(zone_table[zone].races, GET_RACE(mob))) {
  2082.           zone_table[zone].races[strlen(zone_table[zone].races)] = GET_RACE(mob);
  2083.         }
  2084.  
  2085.       last_cmd = 1;
  2086.       master = mob;
  2087.     } else
  2088.       last_cmd = 0;
  2089.     break;
  2090.  
  2091.       case 'C': /* read a mobile.  Charm them to follow prev. */
  2092.     if ((mob_index[ZCMD.arg1].number < ZCMD.arg2) && !CheckKillFile(mob_index[ZCMD.arg1].virtual)) {
  2093.       mob = read_mobile(ZCMD.arg1, REAL);
  2094.       mob->specials.zone = zone;
  2095.  
  2096.       if (GET_RACE(mob)>RACE_GNOME)
  2097.         if (!strchr(zone_table[zone].races, GET_RACE(mob))) {
  2098.           zone_table[zone].races[strlen(zone_table[zone].races)] = GET_RACE(mob);
  2099.         }
  2100.  
  2101.       if (master) {
  2102.         char_to_room(mob, master->in_room);
  2103.         /*
  2104.           add the charm bit to the dude.
  2105.           */
  2106.         add_follower(mob, master);
  2107.         SET_BIT(mob->specials.affected_by, AFF_CHARM);
  2108.         SET_BIT(mob->specials.act, ZCMD.arg3);
  2109.       } else {
  2110.         extract_char(mob);
  2111.         last_cmd = 0;
  2112.       }
  2113.       last_cmd = 1;
  2114.     }
  2115.     else
  2116.       last_cmd = 0;
  2117.     break;
  2118.  
  2119.       case 'Z':  /* set the last mobile to this zone */
  2120.     if (mob) {
  2121.       mob->specials.zone = ZCMD.arg1;
  2122.  
  2123.       if (GET_RACE(mob)>RACE_GNOME)
  2124.         if (!strchr(zone_table[ZCMD.arg1].races, GET_RACE(mob))) {
  2125.        zone_table[ZCMD.arg1].races[strlen(zone_table[ZCMD.arg1].races)] = 
  2126.          GET_RACE(mob);
  2127.         }
  2128.     }
  2129.         break;
  2130.     
  2131.       case 'O': /* read an object */
  2132.     if (obj_index[ZCMD.arg1].number < ZCMD.arg2) {
  2133.       if (ZCMD.arg3 >= 0 && ((rp = real_roomp(ZCMD.arg3)) != NULL)) {
  2134.         if((ZCMD.if_flag>0&&ObjRoomCount(ZCMD.arg1,rp)<ZCMD.if_flag) ||
  2135.           (ZCMD.if_flag<=0&&ObjRoomCount(ZCMD.arg1,rp)<(-ZCMD.if_flag)+1)){
  2136.           if ((obj = read_object(ZCMD.arg1, REAL)) != NULL) {
  2137.         obj_to_room(obj, ZCMD.arg3);
  2138.         last_cmd = 1;
  2139.           } else {
  2140.         last_cmd = 0;
  2141.           }
  2142.         } else {
  2143.         last_cmd = 0;
  2144.         }
  2145.       } else if (obj = read_object(ZCMD.arg1, REAL)) {
  2146.         sprintf(buf, "Error finding room #%d", ZCMD.arg3);
  2147.         log(buf);
  2148.         last_cmd = 1;
  2149.       }  else {
  2150.         last_cmd = 0;
  2151.       }
  2152.     }
  2153.     break;
  2154.     
  2155.       case 'P': /* object to object */
  2156.     if (obj_index[ZCMD.arg1].number < ZCMD.arg2)  {
  2157.       obj = read_object(ZCMD.arg1, REAL);
  2158.       obj_to = get_obj_num(ZCMD.arg3);
  2159.       if (obj_to && obj) {
  2160.         obj_to_obj(obj, obj_to);
  2161.         last_cmd = 1;
  2162.       } else {
  2163.         last_cmd = 0;
  2164.       }
  2165.     }
  2166.     else
  2167.       last_cmd = 0;
  2168.     break;
  2169.     
  2170.       case 'G': /* obj_to_char */
  2171.     if (obj_index[ZCMD.arg1].number < ZCMD.arg2 &&
  2172.         (obj = read_object(ZCMD.arg1, REAL))) {
  2173.       obj_to_char(obj, mob);
  2174.       last_cmd = 1;
  2175.     } else
  2176.       last_cmd = 0;
  2177.     break;
  2178.     
  2179.       case 'H': /* hatred to char */
  2180.     
  2181.     if (AddHatred(mob, ZCMD.arg1, ZCMD.arg2))
  2182.       last_cmd = 1;
  2183.     else 
  2184.       last_cmd = 0;
  2185.     break;
  2186.     
  2187.       case 'F': /* fear to char */
  2188.     
  2189.     if (AddFears(mob, ZCMD.arg1, ZCMD.arg2))
  2190.       last_cmd = 1;
  2191.     else 
  2192.       last_cmd = 0;
  2193.     break;
  2194.     
  2195.       case 'E': /* object to equipment list */
  2196.     if (obj_index[ZCMD.arg1].number < ZCMD.arg2 &&
  2197.         (obj = read_object(ZCMD.arg1, REAL))) {
  2198.       if (!mob->equipment[ZCMD.arg3]) {
  2199.         equip_char(mob, obj, ZCMD.arg3);
  2200.       } else {
  2201.         sprintf(buf, "eq error - zone %d, cmd %d, item %d, mob %d, loc %d\n", zone, cmd_no, 
  2202.             obj_index[ZCMD.arg1].virtual, mob_index[mob->nr].virtual, ZCMD.arg3);
  2203.         log_sev(buf, 6);
  2204.       }
  2205.         last_cmd = 1;
  2206.       }    else
  2207.         last_cmd = 0;
  2208.     break;
  2209.     
  2210.       case 'D': /* set state of door */
  2211.     rp = real_roomp(ZCMD.arg1);
  2212.     if (rp && rp->dir_option[ZCMD.arg2]) {
  2213.       switch (ZCMD.arg3) {
  2214.       case 0:
  2215.         REMOVE_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
  2216.         REMOVE_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
  2217.         break;
  2218.       case 1:
  2219.         SET_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
  2220.         REMOVE_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
  2221.         break;
  2222.       case 2:
  2223.         SET_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_LOCKED);
  2224.         SET_BIT(rp->dir_option[ZCMD.arg2]->exit_info, EX_CLOSED);
  2225.         break;
  2226.       }
  2227.       last_cmd = 1;
  2228.     } else {
  2229.       /* that exit doesn't exist anymore */
  2230.     }
  2231.     break;
  2232.     
  2233.       default:
  2234.     sprintf(buf, "Undefd cmd in reset table; zone %d cmd %d.\n\r",
  2235.         zone, cmd_no);
  2236.     log(buf);
  2237.     break;
  2238.       }
  2239.     else
  2240.       last_cmd = 0;
  2241.     
  2242.   }
  2243.  
  2244.   for (j=0;zone_table[zone].races[j];j++) {
  2245.     fprintf(stderr, "%d ", (int)zone_table[zone].races[j]);
  2246.   }
  2247.   fprintf(stderr, "\n");  
  2248.  
  2249.   zone_table[zone].age = 0;
  2250.   zone_table[zone].start = 1;
  2251.  
  2252. }
  2253.  
  2254. #undef ZCMD
  2255.  
  2256. /* for use in reset_zone; return TRUE if zone 'nr' is free of PC's  */
  2257. int is_empty(int zone_nr)
  2258. {
  2259.   struct descriptor_data *i;
  2260.   
  2261.   for (i = descriptor_list; i; i = i->next)
  2262.     if (!i->connected)
  2263.       if (real_roomp(i->character->in_room)->zone == zone_nr)
  2264.     return(0);
  2265.   
  2266.   return(1);
  2267. }
  2268.  
  2269.  
  2270.  
  2271.  
  2272.  
  2273. /*************************************************************************
  2274. *  stuff related to the save/load player system                                  *
  2275. *********************************************************************** */
  2276.  
  2277. /* Load a char, TRUE if loaded, FALSE if not */
  2278. int load_char(char *name, struct char_file_u *char_element)
  2279. {
  2280.   FILE *fl;
  2281.   int player_i;
  2282.   
  2283.   int find_name(char *name);
  2284.   
  2285.   if ((player_i = find_name(name)) >= 0) {
  2286.     
  2287.     if (!(fl = fopen(PLAYER_FILE, "r"))) {
  2288.       perror("Opening player file for reading. (db.c, load_char)");
  2289.       assert(0);
  2290.     }
  2291.     
  2292.     fseek(fl, (long) (player_table[player_i].nr *
  2293.               sizeof(struct char_file_u)), 0);
  2294.     
  2295.     fread(char_element, sizeof(struct char_file_u), 1, fl);
  2296.     fclose(fl);
  2297.     /*
  2298.      **  Kludge for ressurection
  2299.      */
  2300.     char_element->talks[2] = FALSE; /* they are not dead */
  2301.     return(player_i);
  2302.  
  2303.   } else
  2304.     
  2305.     return(-1);
  2306. }
  2307.  
  2308.  
  2309.  
  2310.  
  2311. /* copy data from the file structure to a char struct */    
  2312. void store_to_char(struct char_file_u *st, struct char_data *ch)
  2313. {
  2314.   int i;
  2315.   int max;
  2316.  
  2317.   GET_SEX(ch) = st->sex;
  2318.   ch->player.class = st->class;
  2319.  
  2320.   for (i=MAGE_LEVEL_IND; i< MAX_CLASS; i++)
  2321.     ch->player.level[i] = st->level[i];
  2322.  
  2323.   GET_RACE(ch)  = st->race;
  2324.   
  2325.   ch->player.short_descr = 0;
  2326.   ch->player.long_descr = 0;
  2327.   
  2328.   if (*st->title)    {
  2329.     CREATE(ch->player.title, char, strlen(st->title) + 1);
  2330.     strcpy(ch->player.title, st->title);
  2331.   }  else
  2332.     GET_TITLE(ch) = 0;
  2333.   
  2334.   if (*st->description)    {
  2335.     CREATE(ch->player.description, char, 
  2336.        strlen(st->description) + 1);
  2337.     strcpy(ch->player.description, st->description);
  2338.   } else
  2339.     ch->player.description = 0;
  2340.   
  2341.   ch->player.hometown = st->hometown;
  2342.   
  2343.   ch->player.time.birth = st->birth;
  2344.   ch->player.time.played = st->played;
  2345.   ch->player.time.logon  = time(0);
  2346.   
  2347.   for (i = 0; i <= MAX_TOUNGE - 1; i++)
  2348.     ch->player.talks[i] = st->talks[i];
  2349.   
  2350.   ch->player.weight = st->weight;
  2351.   ch->player.height = st->height;
  2352.   
  2353.   ch->abilities = st->abilities;
  2354.   ch->tmpabilities = st->abilities;
  2355.   ch->points = st->points;
  2356.   
  2357.   SpaceForSkills(ch);
  2358.  
  2359.   if (HowManyClasses(ch) >= 3) {
  2360.     max = 80;    
  2361.   } else if (HowManyClasses(ch) == 2) {
  2362.     max = 87;
  2363.   } else {
  2364.     max = 95;
  2365.   }
  2366.   
  2367.   for (i = 0; i <= MAX_SKILLS - 1; i++) {
  2368.     ch->skills[i].flags = st->skills[i].flags;
  2369.     ch->skills[i].learned = MIN(st->skills[i].learned, max);
  2370.   }
  2371.   
  2372.   ch->specials.spells_to_learn = st->spells_to_learn;
  2373.   ch->specials.alignment    = st->alignment;
  2374.   
  2375.   ch->specials.act          = st->act;
  2376.   ch->specials.carry_weight = 0;
  2377.   ch->specials.carry_items  = 0;
  2378.   ch->specials.pmask        = 0;
  2379.   ch->specials.poofin       = 0;
  2380.   ch->specials.poofout      = 0;
  2381.   ch->points.armor          = 100;
  2382.   ch->points.hitroll        = 0;
  2383.   ch->points.damroll        = 0;
  2384.   ch->specials.affected_by  = st->affected_by;
  2385.   ch->specials.affected_by2  = st->affected_by2;
  2386.   ch->specials.start_room     = st->startroom;
  2387.   ch->player.extra_flags    = st->extra_flags;
  2388.  
  2389.   CREATE(GET_NAME(ch), char, strlen(st->name) +1);
  2390.     strcpy(GET_NAME(ch), st->name);
  2391.   
  2392.   for(i = 0; i <= 4; i++) {
  2393.     ch->specials.apply_saving_throw[i] = 0;
  2394.   }
  2395.   
  2396.   for(i = 0; i <= 2; i++)
  2397.     GET_COND(ch, i) = st->conditions[i];
  2398.   
  2399.   /* Add all spell effects */
  2400.   for(i=0; i < MAX_AFFECT; i++) {
  2401.     if (st->affected[i].type)
  2402.       affect_to_char(ch, &st->affected[i]);
  2403.   }
  2404.   ch->in_room = st->load_room;
  2405.   ch->term = 0;
  2406.   /* set default screen size */
  2407.   ch->size = 25;
  2408.   affect_total(ch);
  2409. } /* store_to_char */
  2410.  
  2411.     
  2412.  
  2413.     
  2414. /* copy vital data from a players char-structure to the file structure */
  2415. void char_to_store(struct char_data *ch, struct char_file_u *st)
  2416. {
  2417.   int i;
  2418.   struct affected_type *af;
  2419.   struct obj_data *char_eq[MAX_WEAR];
  2420.   
  2421.   /* Unaffect everything a character can be affected by */
  2422.   
  2423.   for(i=0; i<MAX_WEAR; i++) {
  2424.     if (ch->equipment[i])
  2425.       char_eq[i] = unequip_char(ch, i);
  2426.     else
  2427.       char_eq[i] = 0;
  2428.   }
  2429.   
  2430.   for(af = ch->affected, i = 0; i<MAX_AFFECT; i++) {
  2431.     if (af) {
  2432.       st->affected[i] = *af;
  2433.       st->affected[i].next = 0;
  2434.       /* subtract effect of the spell or the effect will be doubled */
  2435.       affect_modify( ch, st->affected[i].location,
  2436.             (int)st->affected[i].modifier,
  2437.             st->affected[i].bitvector, FALSE);                         
  2438.       af = af->next;
  2439.     } else {
  2440.       st->affected[i].type = 0;  /* Zero signifies not used */
  2441.       st->affected[i].duration = 0;
  2442.       st->affected[i].modifier = 0;
  2443.       st->affected[i].location = 0;
  2444.       st->affected[i].bitvector = 0;
  2445.       st->affected[i].next = 0;
  2446.     }
  2447.   }
  2448.   
  2449.   if ((i >= MAX_AFFECT) && af && af->next)
  2450.     log("WARNING: OUT OF STORE ROOM FOR AFFECTED TYPES!!!");
  2451.   
  2452.   
  2453.   
  2454.   ch->tmpabilities = ch->abilities;
  2455.   
  2456.   st->birth      = ch->player.time.birth;
  2457.   st->played     = ch->player.time.played;
  2458.   st->played    += (long) (time(0) - ch->player.time.logon);
  2459.   st->last_logon = time(0);
  2460.   
  2461.   ch->player.time.played = st->played;
  2462.   ch->player.time.logon = time(0);
  2463.   
  2464.   st->hometown = ch->player.hometown;
  2465.   st->weight   = GET_WEIGHT(ch);
  2466.   st->height   = GET_HEIGHT(ch);
  2467.   st->sex      = GET_SEX(ch);
  2468.   st->class    = ch->player.class;
  2469.   for (i=MAGE_LEVEL_IND; i< MAX_CLASS; i++) 
  2470.     st->level[i]    = ch->player.level[i];
  2471.   st->race     = GET_RACE(ch);
  2472.  
  2473.   st->abilities = ch->abilities;
  2474.   st->points    = ch->points;
  2475.   st->alignment       = ch->specials.alignment;
  2476.   st->spells_to_learn = ch->specials.spells_to_learn;
  2477.   st->act             = ch->specials.act;
  2478.   st->affected_by      = ch->specials.affected_by;
  2479.   st->affected_by2     = ch->specials.affected_by2;
  2480.   st->startroom =     ch->specials.start_room;
  2481.   st->extra_flags =   ch->player.extra_flags;
  2482.   
  2483.   st->points.armor   = 100;
  2484.   st->points.hitroll =  0;
  2485.   st->points.damroll =  0;
  2486.   
  2487.   if (GET_TITLE(ch))
  2488.     strcpy(st->title, GET_TITLE(ch));
  2489.   else
  2490.     *st->title = '\0';
  2491.   
  2492.   if (ch->player.description)
  2493.     strcpy(st->description, ch->player.description);
  2494.   else
  2495.     *st->description = '\0';
  2496.   
  2497.   
  2498.   for (i = 0; i <= MAX_TOUNGE - 1; i++)
  2499.     st->talks[i] = ch->player.talks[i];
  2500.   
  2501.   for (i = 0; i <= MAX_SKILLS - 1; i++)
  2502.     st->skills[i] = ch->skills[i];
  2503.   
  2504.   strcpy(st->name, GET_NAME(ch) );
  2505.   
  2506.   for(i = 0; i <= 4; i++)
  2507.     st->apply_saving_throw[i] = ch->specials.apply_saving_throw[i];
  2508.   
  2509.   for(i = 0; i <= 2; i++)
  2510.     st->conditions[i] = GET_COND(ch, i);
  2511.   
  2512.   for(af = ch->affected, i = 0; i<MAX_AFFECT; i++) {
  2513.     if (af) {
  2514.       /* Add effect of the spell or it will be lost */
  2515.       /* When saving without quitting               */
  2516.       affect_modify( ch, st->affected[i].location,
  2517.             (int)st->affected[i].modifier,
  2518.             st->affected[i].bitvector, TRUE);
  2519.       af = af->next;
  2520.     }
  2521.   }
  2522.   
  2523.   for(i=0; i<MAX_WEAR; i++) {
  2524.     if (char_eq[i])
  2525.       equip_char(ch, char_eq[i], i);
  2526.   }
  2527.   
  2528.   affect_total(ch);
  2529. } /* Char to store */
  2530.  
  2531.  
  2532.  
  2533.  
  2534. /* create a new entry in the in-memory index table for the player file */
  2535. int create_entry(char *name)
  2536. {
  2537.   int i;
  2538.  
  2539.   if (top_of_p_table == -1)    {
  2540.     CREATE(player_table, struct player_index_element, 1);
  2541.     top_of_p_table = 0;
  2542.   }  else
  2543.     if (!(player_table = (struct player_index_element *) 
  2544.       realloc(player_table, sizeof(struct player_index_element) * 
  2545.           (++top_of_p_table + 1))))
  2546.       {
  2547.     perror("create entry");
  2548.     assert(0);
  2549.       }
  2550.   
  2551.   CREATE(player_table[top_of_p_table].name, char , strlen(name) + 1);
  2552.   
  2553.   /* copy lowercase equivalent of name to table field */
  2554.   for (i = 0; *(player_table[top_of_p_table].name + i) = 
  2555.        LOWER(*(name + i)); i++);
  2556.   
  2557.   player_table[top_of_p_table].nr = top_of_p_table;
  2558.   
  2559.   return (top_of_p_table);
  2560. }
  2561.         
  2562.  
  2563.  
  2564. /* write the vital data of a player to the player file */
  2565. void save_char(struct char_data *ch, sh_int load_room)
  2566. {
  2567.   struct char_file_u st;
  2568.   FILE *fl;
  2569.   char mode[4];
  2570.   int expand;
  2571.   struct char_data *tmp;
  2572.   
  2573.   if (IS_NPC(ch) && !(IS_SET(ch->specials.act, ACT_POLYSELF))) {
  2574.     return;
  2575.   }
  2576.   
  2577.   if (IS_NPC(ch)) {
  2578.     if (!ch->desc) 
  2579.       return;
  2580.     tmp = ch->desc->original;
  2581.     if (!tmp)
  2582.       return;
  2583.     
  2584.   } else {
  2585.     if (!ch->desc)
  2586.       return;
  2587.     tmp = 0;
  2588.   }
  2589.   
  2590.   if (expand = (ch->desc->pos > top_of_p_file))    {
  2591.     strcpy(mode, "a");
  2592.     top_of_p_file++;
  2593.   }  else
  2594.     strcpy(mode, "r+");
  2595.   
  2596.   if (!tmp)
  2597.     char_to_store(ch, &st);
  2598.     else
  2599.       char_to_store(tmp, &st);
  2600.   
  2601.   st.load_room = load_room;
  2602.   
  2603.   strcpy(st.pwd, ch->desc->pwd);
  2604.   
  2605.   if (!(fl = fopen(PLAYER_FILE, mode)))    {
  2606.     perror("save char");
  2607.     assert(0);
  2608.   }
  2609.   
  2610.   if (!expand)
  2611.     fseek(fl, ch->desc->pos * sizeof(struct char_file_u), 0);
  2612.   
  2613.   fwrite(&st, sizeof(struct char_file_u), 1, fl);
  2614.   
  2615.   fclose(fl);
  2616. }
  2617.  
  2618.  
  2619.  
  2620.  
  2621. /* for possible later use with qsort */
  2622. int compare(struct player_index_element *arg1, struct player_index_element 
  2623.     *arg2)
  2624. {
  2625.     return (str_cmp(arg1->name, arg2->name));
  2626. }
  2627.  
  2628.  
  2629.  
  2630.  
  2631. /************************************************************************
  2632. *  procs of a (more or less) general utility nature            *
  2633. ********************************************************************** */
  2634.  
  2635. /* Original fread_string was a memory leaking piece of garbage... -DM */
  2636. char *fread_string(FILE *f1)
  2637. {
  2638.  char buf[MAX_STRING_LENGTH];
  2639.  int i = 0, tmp;
  2640.  
  2641.  buf[0] = '\0';
  2642.  
  2643.  while(i < MAX_STRING_LENGTH - 2) {
  2644.      tmp = fgetc(f1);
  2645.      if(!tmp) {
  2646.         perror("Fread_string");
  2647.         assert(0);
  2648.       }
  2649.  
  2650.      if(tmp == '~')
  2651.         break;
  2652.  
  2653.      buf[i++] = (char)tmp;
  2654.    }
  2655.  
  2656.  if(i == MAX_STRING_LENGTH - 2) { /* We filled the buffer */
  2657.     buf[i] = '\0';
  2658.     log("File too long (fread_string).");
  2659.     while(tmp = fgetc(f1))
  2660.         if(tmp == '~')
  2661.            break;
  2662.   }
  2663.  
  2664.  else
  2665.     buf[i] = '\0';
  2666.  
  2667.  fgetc(f1);
  2668.  
  2669.  return((char *)strdup(buf));
  2670. }
  2671.  
  2672.  
  2673.  
  2674. /* release memory allocated for a char struct */
  2675. void free_char(struct char_data *ch)
  2676. {
  2677.   struct affected_type *af;
  2678.   int i;
  2679.  
  2680.   free(GET_NAME(ch));
  2681.  
  2682.   if (ch->player.title)
  2683.     free(ch->player.title);
  2684.   if (ch->player.short_descr)
  2685.     free(ch->player.short_descr);
  2686.   if (ch->player.long_descr)
  2687.     free(ch->player.long_descr);
  2688.   if(ch->player.description)
  2689.     free(ch->player.description);
  2690.   if (ch->player.sounds)
  2691.     free(ch->player.sounds);
  2692.   if (ch->player.distant_snds)
  2693.     free(ch->player.distant_snds);
  2694.   if (ch->specials.A_list) {
  2695.     for (i=0;i<10;i++) {
  2696.       if (GET_ALIAS(ch, i))
  2697.     free(GET_ALIAS(ch, i));
  2698.     }
  2699.     free(ch->specials.A_list);
  2700.   }
  2701.  
  2702.   for (af = ch->affected; af; af = af->next) 
  2703.     affect_remove(ch, af);
  2704.  
  2705.   if (ch->skills)
  2706.     free(ch->skills);
  2707.  
  2708.   free(ch);
  2709. }
  2710.  
  2711.  
  2712.  
  2713.  
  2714.  
  2715.  
  2716.  
  2717. /* release memory allocated for an obj struct */
  2718. void free_obj(struct obj_data *obj)
  2719. {
  2720.     struct extra_descr_data *this, *next_one;
  2721.  
  2722.     free(obj->name);
  2723.     if(obj->description && *obj->description)
  2724.         free(obj->description);
  2725.     if(obj->short_description && *obj->short_description)
  2726.         free(obj->short_description);
  2727.     if(obj->action_description && *obj->action_description)
  2728.         free(obj->action_description);
  2729.  
  2730.     for( this = obj->ex_description ;
  2731.         (this != 0);this = next_one )
  2732.     {
  2733.         next_one = this->next;
  2734.         if(this->keyword)
  2735.             free(this->keyword);
  2736.         if(this->description)
  2737.             free(this->description);
  2738.         free(this);
  2739.     }
  2740.  
  2741.     free(obj);
  2742. }
  2743.  
  2744.  
  2745.  
  2746.  
  2747.  
  2748.  
  2749. /* read contents of a text file, and place in buf */
  2750. int file_to_string(char *name, char *buf)
  2751. {
  2752.     FILE *fl;
  2753.     char tmp[100];
  2754.  
  2755.     *buf = '\0';
  2756.  
  2757.     if (!(fl = fopen(name, "r")))
  2758.     {
  2759.         perror("file-to-string");
  2760.         *buf = '\0';
  2761.         return(-1);
  2762.     }
  2763.  
  2764.     do
  2765.     {
  2766.         fgets(tmp, 99, fl);
  2767.  
  2768.         if (!feof(fl))
  2769.         {
  2770.             if (strlen(buf) + strlen(tmp) + 2 > MAX_STRING_LENGTH)
  2771.             {
  2772.                 log("fl->strng: string too big (db.c, file_to_string)");
  2773.                 *buf = '\0';
  2774.                 fclose(fl);
  2775.                 return(-1);
  2776.             }
  2777.  
  2778.             strcat(buf, tmp);
  2779.             *(buf + strlen(buf) + 1) = '\0';
  2780.             *(buf + strlen(buf)) = '\r';
  2781.         }
  2782.     }
  2783.     while (!feof(fl));
  2784.  
  2785.     fclose(fl);
  2786.  
  2787.     return(0);
  2788. }
  2789.  
  2790.  
  2791. void ClearDeadBit(struct char_data *ch)
  2792. {
  2793.  
  2794.   FILE *fl;
  2795.   struct char_file_u st;
  2796.  
  2797.   fl = fopen(PLAYER_FILE, "r+");
  2798.   if (!fl) {
  2799.     perror("player file");
  2800.     exit(0);
  2801.   }
  2802.  
  2803.   fseek(fl, ch->desc->pos * sizeof(struct char_file_u), 0);
  2804.   fread(&st, sizeof(struct char_file_u), 1, fl);
  2805.   /*
  2806.    **   this is a serious kludge, and must be changed before multiple
  2807.    **   languages can be implemented
  2808.    */    
  2809.   if (st.talks[2]) {
  2810.     st.talks[2] = 0;  /* fix the 'resurrectable' bit */
  2811.     fseek(fl, ch->desc->pos * sizeof(struct char_file_u), 0);
  2812.     fwrite(&st, sizeof(struct char_file_u), 1, fl);
  2813.     ch->player.talks[2] = 0;  /* fix them both */
  2814.   }
  2815.   fclose(fl);
  2816.  
  2817.   
  2818. }
  2819.  
  2820. /* clear some of the the working variables of a char */
  2821. void reset_char(struct char_data *ch)
  2822. {
  2823.   char buf[100];
  2824.   struct affected_type *af;
  2825.   extern struct dex_app_type dex_app[];
  2826.   
  2827.   int i;
  2828.   
  2829.   for (i = 0; i < MAX_WEAR; i++) /* Initializing */
  2830.     ch->equipment[i] = 0;
  2831.   
  2832.   ch->followers = 0;
  2833.   ch->master = 0;
  2834.   ch->carrying = 0;
  2835.   ch->next = 0;
  2836.   
  2837.   ch->immune = 0;
  2838.   ch->M_immune = 0;
  2839.   ch->susc = 0;
  2840.   ch->mult_att = 1.0;
  2841.   
  2842.   if (!GET_RACE(ch))
  2843.     GET_RACE(ch) = RACE_HUMAN;
  2844.  
  2845.   if ((ch->player.class == 3) && (GET_LEVEL(ch, THIEF_LEVEL_IND))) {
  2846.     ch->player.class = 8;
  2847.     send_to_char("Setting your class to THIEF only.\n\r", ch);
  2848.   }
  2849.  
  2850.   for (i=0;i<MAX_CLASS;i++) {
  2851.     if (GET_LEVEL(ch, i) > LOKI) {
  2852.       GET_LEVEL(ch,i) = 51;
  2853.     }
  2854.   }
  2855.  
  2856.   SET_BIT(ch->specials.act, PLR_ECHO);
  2857.   
  2858.   ch->hunt_dist = 0;
  2859.   ch->hatefield = 0;
  2860.   ch->fearfield = 0;
  2861.   ch->hates.clist = 0;
  2862.   ch->fears.clist = 0;
  2863.   
  2864.   /* AC adjustment */
  2865.   GET_AC(ch) = 100;
  2866.  
  2867.   GET_HITROLL(ch)=0;
  2868.   GET_DAMROLL(ch)=0;
  2869.   
  2870.   ch->next_fighting = 0;
  2871.   ch->next_in_room = 0;
  2872.   ch->specials.fighting = 0;
  2873.   ch->specials.position = POSITION_STANDING;
  2874.   ch->specials.default_pos = POSITION_STANDING;
  2875.   ch->specials.carry_weight = 0;
  2876.   ch->specials.carry_items = 0;
  2877.   ch->specials.spellfail = 101;
  2878.   
  2879.   if (GET_HIT(ch) <= 0)
  2880.     GET_HIT(ch) = 1;
  2881.   if (GET_MOVE(ch) <= 0)
  2882.     GET_MOVE(ch) = 1;
  2883.   if (GET_MANA(ch) <= 0)
  2884.     GET_MANA(ch) = 1;
  2885.   
  2886.   ch->points.max_mana = 0;
  2887.   ch->points.max_move = 0;
  2888.  
  2889.   if (IS_IMMORTAL(ch)) {
  2890.     GET_BANK(ch) = 0;
  2891.     GET_GOLD(ch) = 100000;
  2892.   }
  2893.   
  2894.   if (GET_BANK(ch) > GetMaxLevel(ch)*100000) {
  2895.     sprintf(buf, "%s has %d coins in bank.", GET_NAME(ch), GET_BANK(ch));
  2896.     log(buf);
  2897.   }
  2898.   if (GET_GOLD(ch) > GetMaxLevel(ch)*100000) {
  2899.     sprintf(buf, "%s has %d coins.", GET_NAME(ch), GET_GOLD(ch));
  2900.     log(buf);
  2901.   }
  2902.  
  2903.   /*
  2904.     Class specific Stuff
  2905.     */
  2906.   
  2907.   ClassSpecificStuff(ch);
  2908.  
  2909.   if (HasClass(ch, CLASS_MONK)) {
  2910.     GET_AC(ch) -= MIN(150, (GET_LEVEL(ch, MONK_LEVEL_IND)*5));
  2911.     ch->points.max_move += GET_LEVEL(ch, MONK_LEVEL_IND);
  2912.   }
  2913.  
  2914.   /*
  2915.     racial stuff
  2916.     */
  2917.   SetRacialStuff(ch);
  2918.  
  2919. /*
  2920.   update the affects on the character.
  2921. */
  2922.  
  2923.   ch->specials.sev = 5;
  2924.  
  2925.   for(af = ch->affected; af; af=af->next)
  2926.     affect_modify(ch, af->location, (int)af->modifier, af->bitvector, 
  2927.           TRUE);
  2928.  
  2929.   if (!HasClass(ch, CLASS_MONK))
  2930.     GET_AC(ch) += dex_app[GET_DEX(ch)].defensive;
  2931.   if (GET_AC(ch) > 100)
  2932.     GET_AC(ch) = 100;
  2933.  
  2934.  
  2935. /*
  2936.   clear out the 'dead' bit on characters
  2937. */
  2938.   if (ch->desc)
  2939.     ClearDeadBit(ch);
  2940.  
  2941. }
  2942.  
  2943.  
  2944.  
  2945. /* clear ALL the working variables of a char and do NOT free any space alloc'ed*/
  2946. void clear_char(struct char_data *ch)
  2947. {
  2948.     memset(ch, '\0', sizeof(struct char_data));
  2949.  
  2950.     ch->in_room = NOWHERE;
  2951.     ch->specials.was_in_room = NOWHERE;
  2952.     ch->specials.position = POSITION_STANDING;
  2953.     ch->specials.default_pos = POSITION_STANDING;
  2954.     GET_AC(ch) = 100; /* Basic Armor */
  2955. }
  2956.  
  2957.  
  2958. void clear_object(struct obj_data *obj)
  2959. {
  2960.     memset(obj, '\0', sizeof(struct obj_data));
  2961.  
  2962.     obj->item_number = -1;
  2963.     obj->in_room      = NOWHERE;
  2964.     obj->eq_pos       = -1;
  2965. }
  2966.  
  2967.  
  2968.  
  2969.  
  2970. /* initialize a new character only if class is set */
  2971. void init_char(struct char_data *ch)
  2972. {
  2973.   int i;
  2974.  
  2975.   /* *** if this is our first player --- he be God *** */
  2976.   
  2977.   if (top_of_p_table < 0)    {
  2978.     GET_EXP(ch) = 24000000;
  2979.     GET_LEVEL(ch,0) = IMPLEMENTOR;
  2980.     ch->points.max_hit = 1000;
  2981.   }
  2982.  
  2983.   set_title(ch);
  2984.  
  2985.   ch->player.short_descr = 0;
  2986.   ch->player.long_descr = 0;
  2987.   ch->player.description = 0;
  2988.   
  2989.   ch->player.hometown = number(1,4);
  2990.   
  2991.   ch->player.time.birth = time(0);
  2992.   ch->player.time.played = 0;
  2993.   ch->player.time.logon = time(0);
  2994.   
  2995.   for (i = 0; i < MAX_TOUNGE; i++)
  2996.     ch->player.talks[i] = 0;
  2997.  
  2998.   GET_STR(ch) = 9;
  2999.   GET_INT(ch) = 9;
  3000.   GET_WIS(ch) = 9;
  3001.   GET_DEX(ch) = 9;
  3002.   GET_CON(ch) = 9;
  3003.   GET_CHR(ch) = 9;
  3004.   
  3005.   /* make favors for sex */
  3006.   if (GET_RACE(ch) == RACE_HUMAN) {
  3007.     if (ch->player.sex == SEX_MALE) {
  3008.       ch->player.weight = number(120,180);
  3009.       ch->player.height = number(160,200);
  3010.     } else {
  3011.       ch->player.weight = number(100,160);
  3012.       ch->player.height = number(150,180);
  3013.     }
  3014.   } else if (GET_RACE(ch) == RACE_DWARF || (GET_RACE(ch)==RACE_GNOME)){
  3015.     if (ch->player.sex == SEX_MALE) {
  3016.       ch->player.weight = number(120,180);
  3017.       ch->player.height = number(100,150);
  3018.     } else {
  3019.       ch->player.weight = number(100,160);
  3020.       ch->player.height = number(100,150);
  3021.     }
  3022.   } else if (GET_RACE(ch) == RACE_HALFLING) {
  3023.     if (ch->player.sex == SEX_MALE) {
  3024.       ch->player.weight = number(70,120);
  3025.       ch->player.height = number(80,120);
  3026.     } else {
  3027.       ch->player.weight = number(60,110);
  3028.       ch->player.height = number(70,115);
  3029.     }
  3030.     
  3031.   } else if (GET_RACE(ch) == RACE_ELVEN) {
  3032.     if (ch->player.sex == SEX_MALE) {
  3033.       ch->player.weight = number(100,150);
  3034.       ch->player.height = number(160,200);
  3035.     } else {
  3036.       ch->player.weight = number(80,230);
  3037.       ch->player.height = number(150,180);
  3038.     }
  3039.   } else {
  3040.     if (ch->player.sex == SEX_MALE) {
  3041.       ch->player.weight = number(120,180);
  3042.       ch->player.height = number(160,200);
  3043.     } else {
  3044.       ch->player.weight = number(100,160);
  3045.       ch->player.height = number(150,180);
  3046.     }
  3047.   }
  3048.   
  3049.   ch->points.mana = GET_MAX_MANA(ch);
  3050.   ch->points.hit = GET_MAX_HIT(ch);
  3051.   ch->points.move = GET_MAX_MOVE(ch);
  3052.   
  3053.   ch->points.armor = 100;
  3054.   
  3055.   if (!ch->skills)
  3056.     SpaceForSkills(ch);
  3057.   
  3058.   for (i = 0; i <= MAX_SKILLS - 1; i++)    {
  3059.     if (GetMaxLevel(ch) <IMPLEMENTOR) {
  3060.       ch->skills[i].learned = 0;
  3061.       ch->skills[i].flags = 0;
  3062.     }    else {
  3063.       ch->skills[i].learned = 100;
  3064.       ch->skills[i].flags = 0;
  3065.     }
  3066.   }
  3067.   
  3068.   ch->specials.affected_by = 0;
  3069.   ch->specials.spells_to_learn = 0;
  3070.  
  3071.   for (i = 0; i < 5; i++)
  3072.     ch->specials.apply_saving_throw[i] = 0;
  3073.   
  3074.   for (i = 0; i < 3; i++)
  3075.     GET_COND(ch, i) = (GetMaxLevel(ch) > GOD ? -1 : 24);
  3076. }
  3077.  
  3078. /*
  3079. **  this duplicates the code in room_find, because it is much quicker this way.
  3080. */
  3081. struct room_data *real_roomp(int virtual)
  3082. {
  3083. #if HASH
  3084.   return hash_find(&room_db, virtual);
  3085. #else
  3086.    return((virtual<WORLD_SIZE&&virtual>-1)?room_db[virtual]:0);
  3087. #endif
  3088. }
  3089.  
  3090. /* returns the real number of the monster with given virtual number */
  3091. int real_mobile(int virtual)
  3092. {
  3093.   int bot, top, mid;
  3094.   
  3095.   bot = 0;
  3096.   top = top_of_mobt;
  3097.   
  3098.   /* perform binary search on mob-table */
  3099.   for (;;)
  3100.     {
  3101.       mid = (bot + top) / 2;
  3102.       
  3103.       if ((mob_index + mid)->virtual == virtual)
  3104.     return(mid);
  3105.       if (bot >= top)
  3106.     return(-1);
  3107.       if ((mob_index + mid)->virtual > virtual)
  3108.     top = mid - 1;
  3109.       else
  3110.     bot = mid + 1;
  3111.     }
  3112. }
  3113.  
  3114.  
  3115.  
  3116.  
  3117.  
  3118.  
  3119. /* returns the real number of the object with given virtual number */
  3120. int real_object(int virtual)
  3121. {
  3122.   int bot, top, mid;
  3123.   
  3124.   bot = 0;
  3125.   top = top_of_objt;
  3126.   
  3127.   /* perform binary search on obj-table */
  3128.   for (;;)    {
  3129.       mid = (bot + top) / 2;
  3130.       
  3131.       if ((obj_index + mid)->virtual == virtual)
  3132.     return(mid);
  3133.       if (bot >= top)
  3134.     return(-1);
  3135.       if ((obj_index + mid)->virtual > virtual)
  3136.     top = mid - 1;
  3137.       else
  3138.     bot = mid + 1;
  3139.     }
  3140. }
  3141.  
  3142. int ObjRoomCount(int nr, struct room_data *rp)
  3143. {
  3144.   struct obj_data *o;
  3145.   int count = 0;
  3146.  
  3147.   for (o=rp->contents;o;o=o->next_content) {
  3148.     if (o->item_number == nr) {
  3149.       count++;
  3150.     }
  3151.   }
  3152.   return(count);
  3153. }
  3154.  
  3155. int str_len(char *buf)
  3156. {
  3157.   int i = 0;
  3158.   for(i; buf[i] != '\0'; i++);
  3159.   return(i);
  3160. }
  3161.  
  3162.  
  3163. int load()
  3164. {
  3165.   return(0);
  3166. }
  3167.  
  3168. void gr()
  3169. {
  3170.   return;
  3171. }
  3172.  
  3173. int workhours()
  3174. {
  3175.   return(0);
  3176. }
  3177.  
  3178. void reboot_text(struct char_data *ch, char *arg, int cmd)
  3179. {
  3180.   char buffer[100];
  3181.   struct char_data *p;
  3182.   int i;
  3183.  
  3184.  if(IS_NPC(ch))
  3185.     return;
  3186.  
  3187.  log("Rebooting Essential Text Files.");
  3188.  
  3189.  file_to_string(NEWS_FILE, news);
  3190.  file_to_string(CREDITS_FILE, credits);
  3191.  file_to_string(MOTD_FILE, motd);
  3192.  file_to_string("wizmotd", wmotd);
  3193.  log("Initializing Scripts.");
  3194.  InitScripts();
  3195.  
  3196. /* jdb -- you don't appear to re-install the scripts after you
  3197.    reset the script db
  3198.    */
  3199.  
  3200.   for (p = character_list;p;p=p->next) {
  3201.     for(i = 0; i < top_of_scripts; i++) {
  3202.       if(script_data[i].virtual == mob_index[p->nr].virtual) {
  3203.     SET_BIT(p->specials.act, ACT_SCRIPT);
  3204.     sprintf(buffer, "Setting SCRIPT bit for mobile %s, file %s.", GET_NAME(p), script_data[i].filename);
  3205.     log(buffer);
  3206.     p->script = i;
  3207.     break;
  3208.       }
  3209.     }
  3210.   }
  3211.  return;
  3212. }
  3213.  
  3214.  
  3215. void InitScripts()
  3216. {
  3217.  char buf[255], buf2[255];
  3218.  FILE *f1, *f2;
  3219.  int i, count;
  3220.  struct char_data *mob;
  3221.  
  3222.  if(!script_data)
  3223.     top_of_scripts = 0;
  3224.  
  3225.  /* what is ths for?  turn off all the scripts ??? */
  3226.  /* -yes, just in case the script file was removed, saves pointer probs */
  3227.  
  3228.  for(mob = character_list; mob; mob = mob->next)
  3229.     if(IS_MOB(mob) && IS_SET(mob->specials.act, ACT_SCRIPT)) {
  3230.        mob->commandp = 0;
  3231.        REMOVE_BIT(mob->specials.act, ACT_SCRIPT);
  3232.      }
  3233.  
  3234.  if(!(f1 = fopen("scripts.dat", "r"))) {
  3235.     log("Unable to open file \"scripts.dat\".");
  3236.     return;
  3237.   }
  3238.  
  3239.  if(script_data) {
  3240.     int i = 0;
  3241.     for(;i < top_of_scripts; i++) {
  3242.        free(script_data[i].script);
  3243.        free(script_data[i].filename);
  3244.      }
  3245.     free(script_data);
  3246.     top_of_scripts = 0;
  3247.   }
  3248.  
  3249.  
  3250.  script_data = NULL;
  3251.  script_data = (struct scripts *)malloc(sizeof(struct scripts));
  3252.  
  3253.  while(1) {
  3254.     if(fgets(buf, 254, f1) == NULL)
  3255.        break;
  3256.  
  3257.     if(buf[strlen(buf) - 1] == '\n')
  3258.        buf[strlen(buf) - 1] = '\0';
  3259.  
  3260.     sscanf(buf, "%s %d", buf2, &i);
  3261.  
  3262.     sprintf(buf, "scripts/%s", buf2);
  3263.     if(!(f2 = fopen(buf, "r"))) {
  3264.        sprintf(buf, "Unable to open script \"%s\" for reading.", buf2);
  3265.        log(buf);
  3266.      }
  3267.  
  3268.      else {
  3269.  
  3270.        script_data = (struct scripts *) realloc(script_data, (top_of_scripts + 1) * sizeof(struct scripts));
  3271.  
  3272.        count = 0;
  3273.        while(!feof(f2)) {
  3274.            fgets(buf, 254, f2);
  3275.            if(buf[strlen(buf) - 1] == '\n')
  3276.               buf[strlen(buf) - 1] = '\0';
  3277. /* you really don't want to do a lot of reallocs all at once
  3278. */   
  3279.            script_data[top_of_scripts].script = (struct foo_data *) realloc(script_data[top_of_scripts].script, sizeof(struct foo_data) * (count + 1));
  3280.            script_data[top_of_scripts].script[count].line = (char *) malloc(sizeof(char) * (strlen(buf) + 1));
  3281.  
  3282.            strcpy(script_data[top_of_scripts].script[count].line, buf);
  3283.   
  3284.            count++;
  3285.      }
  3286.  
  3287.        script_data[top_of_scripts].virtual = i;
  3288.        script_data[top_of_scripts].filename = (char *) malloc((strlen(buf2) + 1) * sizeof(char));
  3289.        strcpy(script_data[top_of_scripts].filename, buf2);
  3290.        sprintf(buf, "Script %s assigned to mobile %d.", buf2, i);
  3291.        log(buf);
  3292.        top_of_scripts++;
  3293.        fclose(f2);
  3294.      }
  3295.   }
  3296.  
  3297.   if(top_of_scripts)
  3298.      sprintf(buf, "%d scripts assigned.", top_of_scripts);
  3299.   else
  3300.      sprintf(buf, "No scripts found to assign.");
  3301.   log(buf);
  3302.  
  3303.   fclose(f1);
  3304. }
  3305.  
  3306. int CheckKillFile(int virtual)
  3307. {
  3308.  FILE *f1;
  3309.  char buf[255];
  3310.  int i;
  3311.  
  3312.  if(!(f1 = fopen(killfile, "r"))) {
  3313.     log("Unable to find killfile.");
  3314.     exit(0);
  3315.   }
  3316.  
  3317.  while(fgets(buf, 254, f1) != NULL) {
  3318.     sscanf(buf, "%d", &i);
  3319.     if(i == virtual) {
  3320.        fclose(f1);
  3321.        return(1);
  3322.      }
  3323.   }
  3324.  
  3325.  fclose(f1);
  3326.  return(0);
  3327. }
  3328.  
  3329. void ReloadRooms()
  3330. {
  3331.  int i;
  3332.  
  3333.  for(i = 0; i < number_of_saved_rooms; i++)
  3334.     load_room_objs(saved_rooms[i]);
  3335. }
  3336.  
  3337.  
  3338. void SaveTheWorld()
  3339. {
  3340.   static int ctl=29001;  /* this integer is used to save 1/4th the world
  3341.                 at a time (when i write the save code */
  3342.   char cmd, buf[80];
  3343.   int i, j, arg1, arg2, arg3;
  3344.   struct char_data *p;
  3345.   struct obj_data *o;
  3346.   struct room_data *room;
  3347.   FILE *fp;
  3348.   
  3349.   
  3350.   
  3351.   fp = (FILE *)fopen("world/mobs", "r+");  /* append */
  3352.   
  3353.   if (!fp) {
  3354.     log("Unable to open zone writing file.");
  3355.     return;
  3356.   }
  3357.  
  3358. #if 1
  3359.   if (ctl = 30000) {
  3360.     ctl = 0;    
  3361.   }
  3362.  
  3363.   i = ctl;
  3364.   if (ctl == 0) {
  3365.     ctl = 5000;
  3366.   } else if (ctl == 5000) {
  3367.     ctl = 12000;
  3368.     fseek(fp, 0, 2);  /* seek to the end.. start writing at the end */
  3369.   } else if (ctl == 12000) {
  3370.     ctl = 20000;
  3371.     fseek(fp, 0, 2);
  3372.   } else if (ctl == 20000) {
  3373.     ctl = 30000;
  3374.     fseek(fp, 0, 2);
  3375.   }
  3376. #else
  3377.   i = 0;
  3378. #endif
  3379.   
  3380.   for (; i< ctl; i++) {
  3381.     room = real_roomp(i);
  3382.     if (room && !IS_SET(room->room_flags, DEATH)) {
  3383.       /*
  3384.        *  first write out monsters
  3385.        */
  3386.       for (p = room->people; p; p = p->next_in_room) {
  3387.     if (!IS_PC(p)) {
  3388.       cmd = 'M';
  3389.       arg1 = MobVnum(p);
  3390.       arg2 = mob_index[p->nr].number;
  3391.       arg3 = i;
  3392.       Zwrite(fp, cmd, 0, arg1, arg2, arg3, p->player.short_descr);
  3393.           fprintf(fp, "Z 1 %d 1\n", p->specials.zone);
  3394.  
  3395.       /* save hatreds && fears */
  3396.       if (IS_SET(p->hatefield, HATE_SEX))
  3397.         fprintf(fp, "H 1 %d %d -1\n", OP_SEX, p->hates.sex);
  3398.       if (IS_SET(p->hatefield, HATE_RACE))
  3399.         fprintf(fp, "H 1 %d %d -1\n", OP_RACE, p->hates.race);
  3400.       if (IS_SET(p->hatefield, HATE_GOOD))
  3401.         fprintf(fp, "H 1 %d %d -1\n", OP_GOOD, p->hates.good);
  3402.       if (IS_SET(p->hatefield, HATE_EVIL))
  3403.         fprintf(fp, "H 1 %d %d -1\n", OP_EVIL, p->hates.evil);
  3404.       if (IS_SET(p->hatefield, HATE_CLASS))
  3405.         fprintf(fp, "H 1 %d %d -1\n", OP_CLASS, p->hates.class);
  3406.       if (IS_SET(p->hatefield, HATE_VNUM))
  3407.         fprintf(fp, "H 1 %d %d -1\n", OP_VNUM, p->hates.vnum);
  3408.  
  3409.       if (IS_SET(p->fearfield, FEAR_SEX))
  3410.         fprintf(fp, "H 1 %d %d -1\n", OP_SEX, p->fears.sex);
  3411.       if (IS_SET(p->fearfield, FEAR_RACE))
  3412.         fprintf(fp, "H 1 %d %d -1\n", OP_RACE, p->fears.race);
  3413.       if (IS_SET(p->fearfield, FEAR_GOOD))
  3414.         fprintf(fp, "H 1 %d %d -1\n", OP_GOOD, p->fears.good);
  3415.       if (IS_SET(p->fearfield, FEAR_EVIL))
  3416.         fprintf(fp, "H 1 %d %d -1\n", OP_EVIL, p->fears.evil);
  3417.       if (IS_SET(p->fearfield, FEAR_CLASS))
  3418.         fprintf(fp, "H 1 %d %d -1\n", OP_CLASS, p->fears.class);
  3419.       if (IS_SET(p->fearfield, FEAR_VNUM))
  3420.         fprintf(fp, "H 1 %d %d -1\n", OP_VNUM, p->fears.vnum);
  3421.  
  3422.       for (j = 0; j<MAX_WEAR; j++) {
  3423.         if (p->equipment[j]) {
  3424.           if (p->equipment[j]->item_number >= 0) {
  3425.         cmd = 'E'; 
  3426.         arg1 = ObjVnum(p->equipment[j]);
  3427.         arg2 = obj_index[p->equipment[j]->item_number].number;
  3428.         arg3 = j;
  3429.         strcpy(buf, p->equipment[j]->short_description);
  3430.         Zwrite(fp, cmd,1,arg1, arg2, arg3, 
  3431.                buf);
  3432.         RecZwriteObj(fp, p->equipment[j]);
  3433.           }
  3434.         }
  3435.       }
  3436.       for (o = p->carrying; o; o=o->next_content) {
  3437.         if (o->item_number >= 0) {
  3438.           cmd = 'G';
  3439.           arg1 = ObjVnum(o);
  3440.           arg2 = obj_index[o->item_number].number;
  3441.           arg3 = 0;
  3442.               strcpy(buf, o->short_description);
  3443.           Zwrite(fp, cmd, 1, arg1, arg2, arg3, buf);
  3444.           RecZwriteObj(fp, o);
  3445.         }
  3446.       }
  3447.     }
  3448.       }
  3449.     }
  3450.   }
  3451.   fprintf(fp, "S\n");
  3452.   fclose(fp);
  3453.  
  3454. }
  3455.  
  3456.